Copy-and-patch

Uses your system voice; voice and rate in settings.

Snapshot

≈ 2 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

In computing, copy-and-patch compilation is a simple compiler technique intended for just-in-time compilation (JIT compilation) that uses pattern matching to match pre-generated templates to parts of an abstract syntax tree (AST) or bytecode stream, and emit corresponding pre-written machine code fragments that are then patched to insert memory addresses, register addresses, constants and other parameters to produce executable code. Code not matched by templates can be either be interpreted in the normal way, or code created to directly call interpreter code.

In computing, copy-and-patch compilation is a simple compiler technique intended for just-in-time compilation (JIT compilation) that uses pattern matching to match pre-generated templates to parts of an abstract syntax tree (AST) or bytecode stream, and emit corresponding pre-written machine code fragments that are then patched to insert memory addresses, register addresses, constants and other parameters to produce executable code. Code not matched by templates can be either be interpreted in the normal way, or code created to directly call interpreter code. ==Compilation== While copy-and-patch is a "quick-and-dirty" approach to compilation that is orders of magnitude faster than more rigorous techniques, it often yields code that can in many cases approach the performance of partially optimized code produced by those techniques. Copy-and-patch was first described by Fredrik Kjolstad and Haoran Xu in a 2021 paper. , Xu was working on an implementation for Lua that generates templates automatically, based on high-level language descriptions of the interpreter primitives. , a bytecode-based copy-and-patch implementation was used for the Python 3.13 JIT compiler. In 2025, a bytecode-based implementation of copy-and-patch for R was added in a modified version of R 4.3.2. ==See also== Compile and go system Tracing just-in-time compilation Meta-tracing

Text derived from https://en.wikipedia.org/w/index.php?oldid=1370512720 under CC BY-SA 4.0; modifications have been made.

Sources cited in this revision

Extracted from the cited revision's reference blocks; absent citations are not invented.