一句话:设计实现提前编译(AoT)的 JavaScript 编译器,实验表明其速度可与 JIT 竞争且内存占用显著更低。
当前最快的 JavaScript 生产实现均基于即时编译(JIT),近二十年动态语言实现的研究也几乎集中在 JIT 上,但这并不意味着静态(AoT)编译器没有竞争力:由于针对快速 AoT JavaScript 编译器的投入相对稀少,学界缺乏系统的科学对比。本文介绍了一个 AoT JavaScript 编译器的设计与实现,并以性能分析为核心展开研究。作者报告了两组实验:一组基于标准 JavaScript 基准测试套件,另一组基于新构建的基准,这些新基准在编程风格、作者、程序规模、来源与语言特性覆盖面上都力求多样。第一组实验显示 JIT 编译器占优,这在数十年针对这些测试的优化投入之后是意料之中的;第二组实验则给出更均衡的结果:AoT 编译器生成的程序达到了有竞争力的运行速度,同时内存消耗显著更低。文中还介绍并评估了作者自己发明或从其他系统借鉴的、用于改进 AoT JavaScript 编译的若干技术。
The fastest JavaScript production implementations use just-in-time (JIT) compilation and the vast majority of academic publications about implementations of dynamic languages published during the last two decades focus on JIT compilation. This does not imply that static compilers (AoT) cannot be competitive; as comparatively little effort has been spent creating fast AoT JavaScript compilers, a scientific comparison is lacking. This paper presents the design and implementation of an AoT JavaScript compiler, focusing on a performance analysis. The paper reports on two experiments, one based on standard JavaScript benchmark suites and one based on new benchmarks chosen for their diversity of styles, authors, sizes, provenance, and coverage of the language. The first experiment shows an advantage to JIT compilers, which is expected after the decades of effort that these compilers have paid to these very tests. The second shows more balanced results, as the AoT compiler generates programs that reach competitive speeds and that consume significantly less memory. The paper presents and evaluates techniques that we have either invented or adapted from other systems, to improve AoT JavaScript compilation.