一句话:提出无需改写、无需独立内部格式的 WebAssembly 原地解释器,性能媲美解释定制格式。
WebAssembly(Wasm)是紧凑、规范良好的字节码格式,旨在作为可移植的编译目标并提供接近原生的执行速度,其设计初衷并非直接解释执行。在 JIT 场景中,编译时间与内存消耗严重影响应用启动,因此许多引擎后来采用更快的单遍(baseline)编译器;但 baseline 编译器仍需耗时,并为不常执行的代码浪费代码空间。典型解释器又不可行,于是部分引擎将 Wasm 编译为更紧凑、易解释的格式,这同样耗时耗内存。本文提出一种快速原地解释器,直接解释 Wasm 字节码,无需重写也无需单独格式。评估表明,原地解释 Wasm 代码空间高效且速度快,性能与解释定制设计的内部格式相当,填补了 Wasm 执行层配置中的空白,可实现比以往更快的启动与更低的内存占用。
WebAssembly (Wasm) is a compact, well-specified bytecode format that offers a portable compilation target with near-native execution speed. The bytecode format was specifically designed to be fast to parse, validate, and compile, positioning itself as a portable alternative to native code. It was pointedly not designed to be interpreted directly. Instead, design considerations at the time focused on competing with native code, utilizing optimizing compilers as the primary execution tier. Yet, in JIT scenarios, compilation time and memory consumption critically impact application startup, leading many Wasm engines to later deploy faster single-pass (baseline) compilers. Though faster, baseline compilers still take time and waste code space for infrequently executed code. A typical interpreter being infeasible, some engines resort to compiling Wasm not to machine code, but to a more compact, but easy to interpret format. This still takes time and wastes memory. Instead, we introduce in this article a fast in-place interpreter for WebAssembly, where no rewrite and no separate format is necessary. Our evaluation shows that in-place interpretation of Wasm code is space-efficient and fast, achieving performance on-par with interpreting a custom-designed internal format. This fills a hole in the execution tier space for Wasm, allowing for even faster startup and lower memory footprint than previous engine configurations.