Back to blog

WebAssembly: When It Actually Pays Off, and When It Is Overkill

Wasm is excellent for a narrow set of problems and a liability for everything else. A clear-eyed look at the cases where it earns its complexity.

Low-level code compiling to a browser runtime target

WebAssembly has been "about to change everything" for years. The honest version is narrower: it is a very good answer to a specific class of problem, and an expensive answer to everything else.

What it is

A compact binary instruction format that browsers execute at near-native speed. You write in Rust, C++, Go or similar, compile to a .wasm module, and call it from JavaScript. It runs in the same sandbox as the rest of the page, with no direct DOM access — that still goes through JavaScript.

Where it genuinely wins

  • Heavy computation in the browser. Image and video processing, audio effects, compression, cryptography, physics, 3D geometry. Work that is CPU-bound and runs for hundreds of milliseconds or more.
  • Porting an existing native library. A mature C or C++ codebase — a PDF renderer, a CAD kernel, a codec, a chess engine — reaches the web without a rewrite. This is probably the single most valuable use case in practice.
  • Deterministic, portable execution. Running untrusted plugins or user-supplied logic inside a tight sandbox, on the server as well as the client.
  • Keeping data on the device. Processing sensitive files locally instead of uploading them, which is both a privacy feature and a bandwidth saving.
Compiled binary module loaded by a browser runtime
Wasm shines on CPU-bound work, not on ordinary interface code.

Where it is a bad trade

Building ordinary UI in Wasm is usually a mistake. Every DOM interaction crosses a boundary, the module ships as a large binary that cannot be partially parsed the way JavaScript can, and debugging is harder. If the work being done is fetching some JSON and rendering a list, JavaScript is not the bottleneck and Wasm will make the page heavier and the codebase stranger.

Watch the costs: module size, the transfer cost of copying data across the boundary, a second toolchain in CI, and a smaller pool of developers who can maintain it.

A decision rule

Ask two questions. First, is there a measured, CPU-bound hot path taking more than a few hundred milliseconds? Second, does a mature native library already exist that would take months to reimplement? If the answer to either is yes, Wasm is probably worth it. If the answer to both is no, the performance win you are imagining is more likely to come from shipping less JavaScript, caching better, and optimizing images.

Used precisely, it is one of the most powerful tools on the platform. Used as a general-purpose replacement for JavaScript, it is a lot of complexity in exchange for very little.

WebAssembly: When It Actually Pays Off, and When It Is Overkill — 1WebAssembly: When It Actually Pays Off, and When It Is Overkill — 2WebAssembly: When It Actually Pays Off, and When It Is Overkill — 3
Written by

Hesam Ziaee, a web developer and programmer who builds fast, user-friendly websites with Vue.js, Quasar and Node.js.