IT lexicon › Programming › Copy-and-patch

Copy-and-patch

Programming På svenska → Updated: 2026-11-05

A JIT technique in which precompiled machine-code templates are copied into memory and only the holes — constants, addresses, jump targets — are filled in at run time.

Haoran Xu and Fredrik Kjolstad at Stanford described the method in 2021. At build time a library of small code snippets, called stencils, is compiled with an ordinary optimising compiler such as Clang. Wherever a stencil needs a value known only at run time, it references an external symbol, and the object file's relocation table records exactly which bytes to overwrite. The JIT itself then does little more than memcpy and a few stores.

It compiles orders of magnitude faster than a traditional JIT, and the output beats an interpreter because Clang has already optimised every stencil. CPython 3.13 shipped an experimental JIT built on the technique. The clever part is that the entire backend, register allocation and instruction selection included, is borrowed from a compiler that ran long before the program started.

← Back to the lexicon