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.

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.[1]

As of 2023, Xu was working on an implementation for Lua that generates templates automatically, based on high-level language descriptions of the interpreter primitives.[2]

As of 2024, a bytecode-based copy-and-patch implementation was used for the Python 3.13 JIT compiler.[3][4]

In 2025, a bytecode-based implementation of copy-and-patch for R was added in a modified version of R 4.3.2. [5]

See also

References

  1. ^ Xu, Haoran; Kjolstad, Fredrik (2021-10-15). "Copy-and-patch compilation: a fast compilation algorithm for high-level languages and bytecode". Proceedings of the ACM on Programming Languages. 5 (OOPSLA): 136:1–136:30. arXiv:2011.13127. doi:10.1145/3485513.
  2. ^ Xu, Haoran (2023-05-12). "Building a baseline JIT for Lua automatically". sillycross.github.io. Retrieved 2024-01-11.
  3. ^ "Python 3.13 gets a JIT". tonybaloney.github.io. Retrieved 2024-01-09.
  4. ^ "GH-113464: A copy-and-patch JIT compiler by brandtbucher · Pull Request #113465 · python/cpython". GitHub. Retrieved 2024-01-09.
  5. ^ Kocourek, Matěj; Křikava, Filip; Vitek, Jan (2025-10-09). "Copy-and-Patch Just-in-Time Compiler for R". VMIL '25: Proceedings of the 17th ACM SIGPLAN International Workshop on Virtual Machines and Intermediate Languages. ACM: 12–21. doi:10.1145/3759548.3763370. ISBN 979-8-4007-2164-9.{{cite journal}}: CS1 maint: periodical has ISBN (link)

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.