Skip to content
Awsaf Alam
GitHubLinkedIn

Analyzing performance WebAssembly vs Native Code

— Updated — Backend, WebAssembly — 4 min read

This post is a review of someone else's paper: "Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code" by Abhinav Jangda, Bobby Powers, Emery D. Berger and Arjun Guha (USENIX ATC 2019).

JavaScript has been the primary programming language for web applications. As web apps grew more complex, JavaScript's dynamic typing and just-in-time compilation started to cost real time, both while running and at startup. As a result, solutions that provide both efficiency and security for web applications have been in demand.

While there are various technologies available for running performance-critical code on the web platform, WebAssembly has emerged as a widely adopted solution. It provides a portable, safe, and fast runtime environment for multiple languages and has broad support across major web browsers. Below I go through its features and what the paper found about its speed.

The full version is in the paper "Not So Fast" by Jangda et al. (PDF).

WebAssembly was released in 2017, and all major web browsers now support it. It is a low-level bytecode intended to serve as a compilation target for code written in languages like C, C++, Rust, and Go. It offers portability along with performance and security.

WebAssembly's features include safety, performance, portability, and compact code. WebAssembly provides a sandboxed execution environment for running code in a web browser, which helps protect user data and system integrity by isolating the code from the rest of the system. The low-level code emitted by a C/C++ compiler is optimized ahead-of-time for full machine performance. Portability is essential for code targeting the web to run across all hardware and platform types. Compact code is crucial for reducing load times, saving bandwidth, and improving responsiveness on the web.

According to the paper that introduced WebAssembly (Haas et al., PLDI 2017), seven of the 24 PolyBenchC benchmarks ran within 10% of native code, and almost all were less than 2x slower. WebAssembly implementations kept improving: by 2019, 13 of the 24 were within 10% of native, according to Jangda et al., "Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code" (USENIX ATC 2019).

However, PolybenchC benchmarks are not very practical for real-world applications. Jangda et al. ran the SPEC CPU suite of benchmarks instead, and found that applications compiled to WebAssembly run slower than native code by an average of 45% (Firefox) to 55% (Chrome). The SPEC-CPU benchmark results show a significant speed difference between WebAssembly and native code.

The WebAssembly documentation lists a number of targeted use cases, including simulations, programming language interpreters, virtual machines, POSIX programs, image editing, video editing and image recognition. The high performance of WebAssembly on the scientific kernels in PolybenchC does not suggest that it will perform well given a different sort of application.

To address the problem, Jangda et al. built BROWSIX-WASM, an extension to Browsix that provides system-calls for web apps in JS to run unmodified WebAssembly-compiled Unix applications directly inside the browser. BROWSIX-SPEC is a harness that extends BROWSIX-WASM to allow automated collection of detailed timing and hardware on-chip performance counter information to perform detailed measurements of application performance.

Browsix bridges the gap between conventional operating systems and the browser, enabling programs expecting a Unix-like environment to run directly in the browser. By mapping current browser APIs, such as Web Workers and postMessage, onto low-level Unix primitives, such as processes and system calls, Browsix does this. Browsix only supports JS, not WASM, and uses SharedArrayBuffer for process-kernel communication, which WASM does not support.

In conclusion, WebAssembly has emerged as a widely adopted solution for running performance-critical code on the web platform. Its features include safety, performance, portability, and compact code. While its performance is not yet comparable to native code for all applications, the continuous improvements in WebAssembly implementation make it a promising technology for the future. With the introduction of BROWSIX-WASM and BROWSIX-SPEC, it is possible to run unmodified WebAssembly-compiled Unix applications directly inside the browser, enabling detailed performance measurements of application performance.

SPEC CPU → 45% (Firefox) to 55% (Chrome) slower than native code on average, per Jangda et al.

Reasons:

  1. Poor register allocation
  2. poor instruction selection
  3. extra branches
  4. reserved registers
  5. stack overflow checks
  6. indirect functiona call check

To summarize, the latency was caused due to :

  • some missing optimizations
  • design issues inherent to WASM
  • Restrictions applied by the browser environment.

Evaluation

Jangda et al. used BROWSIX-WASM and BROWSIX-SPEC to evaluate the performance of WebAssembly on three benchmark suites:

  1. SPEC CPU 2006
  2. SPEC CPU2017
  3. PolyBenchC → only for comparison purpose, but do not represent typical workloads

SPEC benchmarks require BROWSIX-WASM to run successfully.

The paper's test setup:

CPU6-Core Intel Xeon E5-1650 v3 with hyperthreading
RAM64 GB
Operating SystemUbuntu 16.04 with Linux kernel v4.4.0
Browsers UsedGoogle Chrome 74.0 and Mozilla Firefox 66.0
Compilation MethodNative code using Clang 4.0 and WebAssembly using BROWSIX-WASM
Number of Executions per Benchmark5
Reported MetricsAverage running time and standard error
Execution Time MeasuredDifference between wall clock time at the start and end of program

Written by Md Awsaf Alam. I'm an AI Product Engineer and R&D Lead at Sourcy, and an FSE 2026 first author.

AboutLinkedInGoogle Scholar