Copy-and-Patch Compilation
summary
Copy-and-patch compiles by copying prebuilt binary stencils into memory and patching relocations and constants at runtime, shifting heavy work to build time. A 17 MB stencil library for a C-like metaprogram generates TPC-H code two orders of magnitude faster than LLVM -O0 and three orders faster than higher optimization levels, with execution often within 24% of LLVM -O3. A WebAssembly baseline compiler uses a 35 KB library and achieves 4.9–6.5x faster compilation and 46–63% better throughput than Liftoff.
AI-written summary · about
chapters (16)
- 0:00The Need For Fast Compilation
- 0:59Existing Approach for Tier 1: In Databases
- 1:42Existing Approach for Tier 1: In WebAssembly
- 4:29The Pareto Frontier
- 5:05Intuition of Copy-and-Patch
- 6:19Why it generates code fast?
- 7:19Why it generates fast code?
- 8:36Binary Stencils
- 9:29The core of the trick
- 9:51When we compile this code...
- 10:21Relocation Is Code Generation
- 11:27Burning in Runtime Constants?
- 11:48Register Allocation?
- 12:27Better Instruction Selection?
- 13:10Code Library Size
- 13:48How can we generate so many variants?
related talks
28mCopy-and-Patch Just-in-Time Compiler for R
14mOn-Stack Replacement for Program Generators and Source-to-Source Compilers
01h 00mBeating Hand Tuned Assembly in Compiled Languages
01h 04mJust-in-Time Compilation: The Next Big Thing?
01h 01mFaster Compile Times and Better Performance: Bringing Just-in-Time Compilation to C++
59mCompilers can be surprising
46mWhat C and C++ can do and when do you need Assembly?
19mReusing Just-in-Time Compiled Code
