编程语言与软件工程2024arxiv.org
Deegen:一个支持 JIT 的动态语言虚拟机生成器
Deegen: A JIT-Capable VM Generator for Dynamic Languages
专业 · 约 90 分钟读完前置知识:编译器基础、解释器与字节码、JIT 编译
导读
论文提出 Deegen,一个面向动态语言的、可生成 JIT 的 VM 生成器/编译器编译器:它从以字节码形式描述的 VM 规范出发,生成解释器和多级 JIT。作者用 Deegen 实现标准兼容的 Lua 5.1 VM(LuaJIT Remake),在 44 个基准上,其解释器平均比 PUC Lua 快 179%、比 LuaJIT 解释器快 31%;baseline JIT 启动延迟可忽略,执行平均比 PUC Lua 快 360%,仅比 LuaJIT 优化 JIT 慢 33%(44 项中 13 项更快)。
HN 关注点:只用 VM 规范自动生成高性能解释器与多级 JIT,能否挑战 LuaJIT 这类手写汇编/高度优化的 VM,以及能否推广到 Python、Ruby 等动态语言。
HN 评论精选
这几条评论里:支持 1 质疑 1 补充 2
支持认可从字节码规范自动生成多级 VM 的价值。
仅从以字节码形式编码的 VM 规范就能得到一个多级 VM,这非常令人兴奋。
tekknolagi查看英文原文
It is very exciting to get a multi-tier VM from just bytecode encoded version of VM spec.
补充给出核心基准结果并附作者演讲、进展记录和代码资料。
论文实现 LJR(标准兼容的 Lua 5.1 VM):44 个基准上,解释器平均比 PUC Lua 快 179%,比 LuaJIT 解释器快 31%;baseline JIT 启动延迟可忽略,执行平均比 PUC Lua 快 360%,仅比 LuaJIT 优化 JIT 慢 33%(44 项中 13 项更快)。作者演讲、幻灯片、持续工作记录和 GitHub 仓库都有链接。
sitkack查看英文原文
> We implement LuaJIT Remake (LJR), a standard-compliant Lua 5.1 VM, using Deegen. Across 44 benchmarks, LJR's interpreter is on average 179% faster than the official PUC Lua interpreter, and 31% faster than LuaJIT's interpreter. LJR's baseline JIT has negligible startup delay, and its execution performance is on average 360% faster than PUC Lua and only 33% slower (but faster on 13/44 benchmarks) than LuaJIT's optimizing JIT. presentation by the author Deegen: A LLVM-based Compiler-Compiler for Dynamic Languages https://www.youtube.com/watch?v=5cAUX9QPj4Y Slides https://aha.stanford.edu/sites/g/files/sbiybj20066/files/media/file/aha_071923_xu_deegen_0.pdf Ongoing work documented here https://sillycross.github.io/ and some comments here https://lobste.rs/s/ftsowh/building_baseline_jit_for_lua https://github.com/luajit-remake/luajit-remake
质疑质疑提升幅度,但认为生成解释器已接近手写汇编,仍落后成熟 JIT VM。
LuaJIT 在 JIT 模式下平均比其解释器快约 3 倍(某些基准可达 10 倍),LuaJIT JIT 平均比 PUC Lua 5.1 快约 8 倍;所以 Deegen 比 PUC Lua 快 2 倍、比 LuaJIT 解释器快 1.3 倍并不惊艳。但 LuaJIT 解释器是汇编写的,可推断手写汇编解释器相对生成解释器只快约 30%,因此再手写汇编解释器已不值得(考虑跨平台迁移成本更不值)。另一方面,Deegen 生成的 VM 明显慢于 Mono/CoreCLR 的 JIT 模式。
Rochus查看英文原文
> We implement LuaJIT Remake (LJR)[...] using Deegen. Across 44 benchmarks, LJR's interpreter is on average 179% faster than the official PUC Lua interpreter, and 31% faster than LuaJIT's interpreter. Well, LuaJIT in JIT mode is about factor 3 faster on average than LuaJIT in interpreter mode (depending on the benchmark up to ten times). And LuaJIT in JIT mode is e.g. factor 8 faster on average than PUC Lua 5.1 (see e.g. http://software.rochus-keller.ch/are-we-fast-yet_Lua_results_2024-06-20.pdf for more information). So if Degen is factor 2 faster than PUC Lua or factor 1.3 faster than the LuaJIT interpreter, this is not very impressive. But since the LuaJIT interpreter is written in assembler, we might conclude that the speed-up of a manual assembler implementation compared to a generated interpreter is about 30%. Therefore it's no longer worth the effort to implement an interpreter in assembler (even less if we consider cross-platform migration costs). But on the other hand the Degen generated VM is significantly slower than e.g. the Mono VM or CoreCLR in JIT mode (see e.g. https://github.com/rochus-keller/Oberon/blob/master/testcases/Are-we-fast-yet/Are-we-fast-yet_results_linux.pdf).
补充引用论文称生成代码质量接近专家手写汇编。
Deegen 生成的解释器、baseline JIT 和 JIT 代码的反汇编,可与最先进 VM 中汇编专家手写的汇编代码相媲美。
igouy查看英文原文
"the disassembly of the Deegen-generated interpreter, baseline JIT, and the generated JIT code rivals the assembly code hand-written by assembly experts in state-of-the-art VMs."
相关资源
从这篇论文所有 HN 讨论帖的全部评论里整理出来的链接。
历次讨论
- 2024Hacker News 讨论帖46 分 · 17 评
- 2024Hacker News 讨论帖116 分 · 22 评
同领域还值得读
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 分钟编辑精选