Skip to main content
QUICK REVIEW

[论文解读] Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code

Abhinav Jangda, Bobby Powers|arXiv (Cornell University)|Jan 25, 2019
Security and Verification in Computing参考文献 19被引用 47
一句话总结

本文构建了 Browsix-Wasm 和 Browsix-SPEC,在浏览器中运行未修改的 Unix/WebAssembly 应用,并进行大规模 SPEC CPU 基准测试评估,结果显示 WebAssembly 在 Chrome 上比本地慢 1.55 倍,在 Firefox 上慢 1.45 倍,同时存在显著差距和若干效率问题被识别。

ABSTRACT

All major web browsers now support WebAssembly, a low-level bytecode intended to serve as a compilation target for code written in languages like C and C++. A key goal of WebAssembly is performance parity with native code; previous work reports near parity, with many applications compiled to WebAssembly running on average 10% slower than native code. However, this evaluation was limited to a suite of scientific kernels, each consisting of roughly 100 lines of code. Running more substantial applications was not possible because compiling code to WebAssembly is only part of the puzzle: standard Unix APIs are not available in the web browser environment. To address this challenge, we build Browsix-Wasm, a significant extension to Browsix that, for the first time, makes it possible to run unmodified WebAssembly-compiled Unix applications directly inside the browser. We then use Browsix-Wasm to conduct the first large-scale evaluation of the performance of WebAssembly vs. native. Across the SPEC CPU suite of benchmarks, we find a substantial performance gap: applications compiled to WebAssembly run slower by an average of 45% (Firefox) to 55% (Chrome), with peak slowdowns of 2.08x (Firefox) and 2.5x (Chrome). We identify the causes of this performance degradation, some of which are due to missing optimizations and code generation issues, while others are inherent to the WebAssembly platform.

研究动机与目标

  • 推动并实现使用未修改的 Unix 应用在浏览器中对 WebAssembly 进行大规模、公开、公平的基准测试。
  • 开发 Browsix-Wasm,使在浏览器中运行的 Unix 程序(WebAssembly 编译)开销最小化。
  • 创建 Browsix-SPEC,在浏览器中自动化 SPEC CPU2006/2017 和 PolyBenchC 基准测试,并收集详细的时间和硬件计数数据。
  • 对 WebAssembly 与本地代码进行定量比较,并分析性能差距的根本原因。
  • 为实现者提供可操作的建议,以缩小 WebAssembly 的性能差距。

提出的方法

  • 将 Browsix 扩展为 Browsix-Wasm,使在浏览器中运行未修改的 WebAssembly Unix 程序,并实现优化的内核集成。
  • 开发 Browsix-SPEC,编排浏览器实例、基准资源,并为浏览器内的 SPEC 与 PolyBenchC 基准测试收集性能计数器。
  • 将基准测试编译为本地(Clang)和 WebAssembly(Browsix-Wasm),并在 Chrome 与 Firefox 上测量,且不修改浏览器代码。
  • 使用性能计数器分析 WebAssembly 变慢的原因,包括寄存器压力、指令混合和分支行为。
  • 将 WebAssembly 与 asm.js 进行比较,以量化相对改进并验证先前关于相较于 asm.js 的加速说法。
  • 提供执行时间矩阵及基于计数器的解释,以指导 WebAssembly 后端的优化。

实验结果

研究问题

  • RQ1在浏览器中,WebAssembly 的性能相对于本地代码在大型真实世界基准集(SPEC CPU2006/2017)与 PolyBenchC 上的表现如何?
  • RQ2相对于本地代码,观察到的 WebAssembly 慢的主导因素有哪些(例如寄存器分配、指令数量、分支、内存行为等)?
  • RQ3Browsix-Wasm/Browsix-SPEC 基础设施本身的开销是多少,是否会抵消或使性能结论失效?
  • RQ4WebAssembly 是否在 Chrome 与 Firefox 上持续优于 asm.js,且优势幅度是多少?
  • RQ5可以为实现者提供哪些实用建议,以缩小 WebAssembly 与本地性能的差距?

主要发现

  • 在 Chrome 上,WebAssembly 相较本地在 SPEC 基准测试平均慢 1.55 倍,在 Firefox 上慢 1.45 倍,峰值慢速分别为 Chrome 的 2.5x 和 Firefox 的 2.08x。
  • 在 Chrome 中,15 个 SPEC 基准中有 7 个接近本地 1.5 倍内;在 Firefox 中同样有 7/15。
  • WebAssembly 相较 asm.js 在 Chrome 的平均提升为 1.54x,在 Firefox 为 1.39x;在最佳情形下,WebAssembly 对比最佳 asm.js 的提升约为 1.3x。
  • 与本地相比,WebAssembly 的加载和存储数量增加(Chrome:加载 2.02x,存储 2.30x;Firefox:加载 1.92x,存储 2.16x),分支更多,指令缓存未命中增多,导致执行变慢。
  • 在矩阵乘法中,WebAssembly 比本地慢 2x–3.4x,突显代码生成与寄存器使用方面的低效。
  • 性能计数器分析揭示寄存器压力增加、寄存器分配较差(Chrome/Firefox 使用线性扫描,而 Clang 使用贪心图着色)、以及对 x86寻址模式的低利用率,是关键的降级因素。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。