Copy-and-Patch Just-in-Time Compiler for R
summary
Implements a copy‑and‑patch baseline JIT for GNU R by extracting interpreter instruction bodies into stencils, emitting native code at runtime, and patching 30‑hole on average relocations; prototype compiles any R function on x86_64 Linux, needs ~1.2k C lines plus 2.5k bytecode ports and minor GNUR VM symbol exposure, compiles at 980 bytecode instructions/ms, achieves 1.15x–1.91x speedup (geomean 1.26x) and makes 82% of relocations relative so the approach is feasible and yields modest real‑world gains.
AI-written summary · about
chapters (14)
- 0:00Introduction
- 1:04What makes R slow and hard to optimize
- 2:09Copy-and-patch JIT explained
- 4:18Stencil library runtime
- 6:44Adapting to R's bytecode
- 7:47Specializing constants
- 8:51Self-modifying for loops
- 12:26Handling x86-64 relocations
- 14:55Optimizing memory jumps
- 15:39Implementation details
- 16:22Benchmark setup results
- 18:31Versus CPython copy-and-patch
- 19:36Conclusion future work
- 19:56Q&A
related talks
15mCopy-and-Patch Compilation
19mReusing Just-in-Time Compiled Code
26mAn Analysis of Compiled Code Reusability in Dynamic Compilation
36mAccelerate RISC-V Instruction Set Simulation by Tiered JIT Compilation
44mBuild Your Own VM with JIT Compilation for Dummies
20mBYOJ: Build your own JIT with Ruby
45mTwo-level Just-in-Time Compilation with One Interpreter and One Engine
40mJoy of Meta-Tracing Just-in-Time Compilation: More Than Just a VM Generator
