Compilers face a intrinsic tradeoff between compilation speed and code quality. The tradeoff is particularly stark in a dynamic setting where JIT compilation time contributes to application runtime. Many systems now employ multiple compilation tiers, where one tier offers fast compile speed while another has much slower compile speed but produces higher quality code. With proper heuristics on when to use each, the overall performance is better than using either compiler in isolation. At the introduction of WebAssembly into the Web platform in 2017, most engines employed optimizing compilers and pre-compiled entire modules before execution. Yet since that time, all Web engines have introduced new "baseline" compiler tiers for Wasm to improve startup time. Further, many new non-web engines have appeared, some of which also employ simple compilers. In this paper, we demystify single-pass compilers for Wasm, explaining their internal algorithms and tradeoffs, as well as providing a detailed empirical study of those employed in production. We show the design of a new single-pass compiler for a research Wasm engine that integrates with an in-place interpreter and host garbage collector using value tags. In experiments, we measure the effectiveness of optimizations targeting the cost of value tags, the relative compile speed and execution time of six baseline compilers, and place these baseline compilers in the tradeoff space with other execution tiers for Wasm.
翻译:编译器在编译速度与代码质量之间面临固有权衡。在即时编译时间直接影响应用程序运行时的动态场景中,这种权衡尤为突出。许多系统现采用多级编译架构,其中一级提供快速编译速度,另一级则以显著更慢的编译速度生成更高质量的代码。通过合理启发式方法选择何时使用各层级,整体性能优于单独使用任一编译器。2017年WebAssembly引入Web平台时,大多数引擎采用优化编译器并在执行前预编译整个模块。然而自那时起,所有Web引擎均已为Wasm引入新的“基线”编译层级以改善启动时间。此外,许多新兴非Web引擎也采用了简单编译器。本文揭秘了Wasm单遍编译器,阐释其内部算法与权衡,并对生产环境中的此类编译器进行了详细实证研究。我们展示了一个研究型Wasm引擎中新单遍编译器的设计,该编译器通过值标签与原地解释器和宿主垃圾回收器集成。实验测定了针对值标签成本的优化效果、六种基线编译器的相对编译速度与执行时间,并将这些基线编译器置于Wasm其他执行层级的权衡空间中进行了定位。