encyclopegia.org

Copy-and-patch

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

References

No reference rows published for this article.

Cite this article

MLA

"Copy-and-patch." encyclopegia.org, 2026, https://encyclopegia.org/wiki/copy-and-patch. Accessed 24 November 2026.

Chicago

"Copy-and-patch." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/copy-and-patch.

APA

encyclopegia.org. (2026). Copy-and-patch. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/copy-and-patch

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Copy

stub · references available

Cut Copy

stub · references available

Patch Adams

stub · references available

film copy

stub · references available

patch test

stub · references available

Carbon Copy

stub · references available

Miss Spider's Sunny Patch Friends

stub · references available

Cabbage Patch Kids

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1370512720 · 0.5 · snapshot enwiki-001370512720

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.