Copy-and-Patch Compilation: A Fast Compilation Algorithm for High-Level Languages and BytecodeVirtual
Fri 22 Oct 2021 18:50 - 19:05 at Zurich B - Optimization - mirror Chair(s): Tony Hosking
Fast compilation is important when compilation occurs at runtime, such as query compilers in modern database systems and WebAssembly virtual machines in modern browsers. We present copy-and-patch, an extremely fast compilation technique that also produces good quality code. It is capable of lowering both high-level languages and low-level bytecode programs to binary code, by stitching together code from a large library of binary implementation variants. We call these binary implementations stencils because they have holes where missing values must be inserted during code generation. We show how to construct a stencil library and describe the copy-and-patch algorithm that generates optimized binary code.
We demonstrate two use cases of copy-and-patch: a compiler for a high-level C-like language intended for metaprogramming and a compiler for WebAssembly. Our high-level language compiler has negligible compilation cost: it produces code from an AST in less time than it takes to construct the AST. We have implemented an SQL database query compiler on top of this metaprogramming system and show that on TPC-H database benchmarks, copy-and-patch generates code two orders of magnitude faster than LLVM -O0 and three orders of magnitude faster than higher optimization levels. The generated code runs an order of magnitude faster than interpretation and 14% faster than LLVM -O0. Our WebAssembly compiler generates code 4.9X-6.5X faster than Liftoff, the WebAssembly baseline compiler in Google Chrome. The generated code also outperforms Liftoff's by 39%-63% on the Coremark and PolyBenchC WebAssembly benchmarks.
Fri 22 OctDisplayed time zone: Central Time (US & Canada) change
10:50 - 12:10 | |||
10:50 15mTalk | Copy-and-Patch Compilation: A Fast Compilation Algorithm for High-Level Languages and BytecodeVirtual OOPSLA DOI Pre-print | ||
11:05 15mTalk | VESPA: Static Profiling for Binary OptimizationVirtual OOPSLA Angelica Moreira Federal University of Minas Gerais, Guilherme Ottoni Facebook, Fernando Magno Quintão Pereira Federal University of Minas Gerais DOI | ||
11:20 15mTalk | A Derivative-Based Parser Generator for Visibly Pushdown GrammarsIn-Person OOPSLA Xiaodong Jia Pennsylvania State University, Ashish Kumar Pennsylvania State University, Gang (Gary) Tan Pennsylvania State University DOI | ||
11:35 35mLive Q&A | Discussion, Questions and Answers OOPSLA |
18:50 - 20:10 | |||
18:50 15mTalk | Copy-and-Patch Compilation: A Fast Compilation Algorithm for High-Level Languages and BytecodeVirtual OOPSLA DOI Pre-print | ||
19:05 15mTalk | VESPA: Static Profiling for Binary OptimizationVirtual OOPSLA Angelica Moreira Federal University of Minas Gerais, Guilherme Ottoni Facebook, Fernando Magno Quintão Pereira Federal University of Minas Gerais DOI | ||
19:20 15mTalk | A Derivative-Based Parser Generator for Visibly Pushdown GrammarsIn-Person OOPSLA Xiaodong Jia Pennsylvania State University, Ashish Kumar Pennsylvania State University, Gang (Gary) Tan Pennsylvania State University DOI | ||
19:35 35mLive Q&A | Discussion, Questions and Answers OOPSLA |