https://arxiv.org/abs/2011.13127 Skip to main content Cornell University We gratefully acknowledge support from the Simons Foundation, member institutions, and all contributors. Donate arxiv logo > cs > arXiv:2011.13127 [ ] Help | Advanced Search [All fields ] Search arXiv logo Cornell University Logo [ ] GO quick links * Login * Help Pages * About Computer Science > Programming Languages arXiv:2011.13127 (cs) [Submitted on 26 Nov 2020 (v1), last revised 15 Sep 2021 (this version, v3)] Title:Copy-and-Patch Compilation: A fast compilation algorithm for high-level languages and bytecode Authors:Haoran Xu, Fredrik Kjolstad View a PDF of the paper titled Copy-and-Patch Compilation: A fast compilation algorithm for high-level languages and bytecode, by Haoran Xu and Fredrik Kjolstad View PDF Abstract: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. Subjects: Programming Languages (cs.PL) Cite as: arXiv:2011.13127 [cs.PL] (or arXiv:2011.13127v3 [cs.PL] for this version) https://doi.org/10.48550/arXiv.2011.13127 Focus to learn more arXiv-issued DOI via DataCite https://doi.org/10.1145/3485513 Related DOI: Focus to learn more DOI(s) linking to related resources Submission history From: Haoran Xu [view email] [v1] Thu, 26 Nov 2020 05:03:16 UTC (599 KB) [v2] Tue, 14 Sep 2021 02:41:43 UTC (1,027 KB) [v3] Wed, 15 Sep 2021 01:07:34 UTC (1,027 KB) Full-text links: Access Paper: View a PDF of the paper titled Copy-and-Patch Compilation: A fast compilation algorithm for high-level languages and bytecode, by Haoran Xu and Fredrik Kjolstad * View PDF * TeX Source * Other Formats view license Current browse context: cs.PL < prev | next > new | recent | 2011 Change to browse by: cs References & Citations * NASA ADS * Google Scholar * Semantic Scholar DBLP - CS Bibliography listing | bibtex Haoran Xu Fredrik Kjolstad a export BibTeX citation Loading... BibTeX formatted citation x [loading... ] Data provided by: Bookmark BibSonomy logo Reddit logo (*) Bibliographic Tools Bibliographic and Citation Tools [ ] Bibliographic Explorer Toggle Bibliographic Explorer (What is the Explorer?) [ ] Litmaps Toggle Litmaps (What is Litmaps?) [ ] scite.ai Toggle scite Smart Citations (What are Smart Citations?) ( ) Code, Data, Media Code, Data and Media Associated with this Article [ ] Links to Code Toggle CatalyzeX Code Finder for Papers (What is CatalyzeX?) [ ] DagsHub Toggle DagsHub (What is DagsHub?) [ ] GotitPub Toggle Gotit.pub (What is GotitPub?) [ ] Links to Code Toggle Papers with Code (What is Papers with Code?) [ ] ScienceCast Toggle ScienceCast (What is ScienceCast?) ( ) Demos Demos [ ] Replicate Toggle Replicate (What is Replicate?) [ ] Spaces Toggle Hugging Face Spaces (What is Spaces?) [ ] Spaces Toggle TXYZ.AI (What is TXYZ.AI?) ( ) Related Papers Recommenders and Search Tools [ ] Link to Influence Flower Influence Flower (What are Influence Flowers?) [ ] Connected Papers Toggle Connected Papers (What is Connected Papers?) [ ] Core recommender toggle CORE Recommender (What is CORE?) * Author * Venue * Institution * Topic ( ) About arXivLabs arXivLabs: experimental projects with community collaborators arXivLabs is a framework that allows collaborators to develop and share new arXiv features directly on our website. Both individuals and organizations that work with arXivLabs have embraced and accepted our values of openness, community, excellence, and user data privacy. arXiv is committed to these values and only works with partners that adhere to them. Have an idea for a project that will add value for arXiv's community? Learn more about arXivLabs. Which authors of this paper are endorsers? | Disable MathJax (What is MathJax?) * About * Help * Click here to contact arXiv Contact * Click here to subscribe Subscribe * Copyright * Privacy Policy * Web Accessibility Assistance * arXiv Operational Status Get status notifications via email or slack