Copy-and-patch
Appearance
Copy-and-patch compilation is a compiler technique that uses pre-generated templates to match parts of a bytecode stream, and emit corresponding machine code that is then patched to insert memory addresses, register addresses, constants and other parematers. Code not matched by templates can be either be interpreted in the normal way, or code created to directly call interpreter code.
While copy-and-patch is a "quick-and-dirty" approach to compilation, it yields code that can in many cases approach the performance of more rigorous compiler techniqujes.
Copy-and-patch was first described by Fredrik Kjolstad and Haoran Xu in a 2021 paper.[1] It is used for the Python 3.13 JIT compiler.[2]
References
- ^ 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.
- ^ "Python 3.13 gets a JIT". tonybaloney.github.io. Retrieved 2024-01-09.