编程语言与软件工程2021arxiv.org编辑精选
Copy-and-Patch:面向高级语言和字节码的快速编译
Copy-and-Patch: Fast compilation for high-level languages and bytecode (2020)
进阶 · 约 90 分钟读完前置知识:编译器后端基础、JIT 编译概念、LLVM 基础
导读
这篇论文提出 Copy-and-Patch 编译技术,用于加速高级语言和字节码的编译。其核心做法是预先编译好代码模板,运行时通过复制模板并用编译器后端快速“打补丁”生成机器码,从而在保持高层语言语义的同时实现极快的编译速度。
HN 关注点:是因为这种技术可能大幅提升 JIT 编译速度,并讨论它能否应用于 LLVM、WASM 运行时、模拟器等实际场景。
HN 评论精选
这几条评论里:补充 3
补充询问该技术能否用于 GraphQL-to-SQL 转译等非传统 JIT 场景,并期待 LLVM/WASM 运行时采纳
作者在吗?这个技术很有意思。我想知道它是否适用于业务逻辑层面做 JIT 编译的应用。现实用例:Hasura 本质上是一个 Haskell 写的 GraphQL 到 SQL 的 JIT 编译器/转译器,它先解析、降低到内部 IR,再翻译成特定 SQL 方言。不知道这套方法能否用在这种场景?另外很期待看到 LLVM 或主流 WASM 运行时是否采用这项技术,虽然我没完全读懂论文,但纸面上看加速幅度似乎很大。
gavinray查看英文原文
Are the authors of this paper present/the ones who posted? This is really interesting. One thing I'm curious about -- is this technique applicable to applications which do JIT "compilation" in the business-logic/abstract sense of the term? Realworld usecase: Hasura is fundamentally a Haskell GraphQL-to-SQL JIT compiler/transpiler. It parses, lowers to an internal IR format, and then translates to a specific SQL dialect. I'm wondering if any of this would carry over to a usecase like that? https://github.com/hasura/graphql-engine/blob/master/server/src-lib/Hasura/RQL/IR/Select.hs https://github.com/hasura/graphql-engine/blob/master/server/src-lib/Hasura/Backends/Postgres/Translate/Select.hs Nonetheless, will be interesting to see whether this technique will get adopted by LLVM or some of the major WASM runtimes. I won't pretend to understand the majority of what the writeup stated, but on paper it seems a huge speedup?
补充提议将该技术用于模拟器的动态重编译核心,看重其跨平台透明性
我想听听大家对我用 PochiVM 为模拟器添加动态重编译核心的看法:模拟器识别热点代码块,生成类 C 结构(或理想情况下是 AST),然后用 Copy-and-Patch 算法生成并执行对应的机器码。能够回调宿主方法、处理异常语义,同时对目标平台架构完全透明,这对跨平台模拟器来说似乎很理想。
kev_emu查看英文原文
I would be interested in your thoughts on using PochiVM as a means to add a dynamic re-compiling core for emulators. The emulator would identify hot code blocks, generate C like constructs (or ideally the AST) and use the 'Copy-and-Patch Compilation' algorithm to generate and execute the relevant machine code. The ability to call back to host methods, handle exception semantics and all the while being totally oblivious to the platform architecture that the machine code is produced for seems ideal for an emulator designed to run on multiple platforms.
补充指出 Copy-and-Patch 呼应了 compile 一词“汇编、拼合”的本义
这不就是 compile 这个动词最初的含义、回归了原始的做法吗?(及物动词)把东西拼在一起;汇集;从各种来源收集材料制成。塞缪尔·约翰逊编纂了最具影响力的英语词典之一。
erwan577查看英文原文
Isn't it the first sense of the verb to compile and a return to the original way of doing things ? (transitive) To put together; to assemble; to make by gathering things from various sources. Samuel Johnson compiled one of the most influential dictionaries of the English language.
相关资源
从这篇论文所有 HN 讨论帖的全部评论里整理出来的链接。
历次讨论
- 2021Hacker News 讨论帖30 分 · 7 评
- 2024Hacker News 讨论帖182 分 · 50 评
同领域还值得读
Google 的软件工程(2017)
Software Engineering at Google (2017)
介绍了 Google 的软件工程实践,包括其单一代码库(monorepo)、几乎全部开发在主干进行而非分支、代码审查、构建系统 Blaze、协议缓冲区等工具与流程,并讨论了频繁重…
编程语言与软件工程2017 · 1,127 分 · 465 评 · 引用 15入门 · 约 45 分钟编辑精选Peter Naur:编程作为理论构建 (1985)
Peter Naur – Programming as Theory Building (1985)
Peter Naur 1985 年的经典论文《Programming as Theory Building》提出:编程的本质不是写代码或文档,而是在程序员头脑中构建对程序及其运行…
编程语言与软件工程2016 · 629 分 · 74 评入门 · 约 45 分钟编辑精选SciPy 1.0:Python 科学计算的基础算法
SciPy 1.0: fundamental algorithms for scientific computing in Python
这篇发表于 Nature Methods 的论文介绍了 SciPy 1.0——Python 科学计算生态的基石库,涵盖其核心算法模块(优化、积分、插值、线性代数等)、软件架构与社…
编程语言与软件工程2020 · 387 分 · 98 评入门 · 约 45 分钟编辑精选Lisp 的历史(1979)
History of Lisp (1979)
这是 Lisp 发明者 John McCarthy 于 1979 年为 HOPL(编程语言史)会议撰写的回顾文章,讲述 Lisp 的起源、设计动机与早期演进,文中也涉及 if 表…
编程语言与软件工程2018 · 352 分 · 44 评入门 · 约 45 分钟编辑精选使用 NumPy 进行数组编程
Array Programming with NumPy
这篇 Nature 文章介绍 NumPy 的数组编程模型及其在科学计算中的核心作用:以 ndarray 为中心,通过向量化操作让 Python 高效处理多维数组。
编程语言与软件工程2020 · 318 分 · 134 评入门 · 约 40 分钟编辑精选