Introduction to WebAssembly
1.1 What is WebAssembly?
WebAssembly (Wasm) is a binary instruction format for a stack-based virtual machine. It's designed as a portable compilation target for languages like C, C++, Rust, and Go, enabling deployment on the web and beyond.
Official design goals:
Fast: near-native execution speed, with fast decoding and compilation (streaming).
Safe: a sandboxed, memory-safe execution environment with no access to the host except through imports.
Portable: hardware-, language-, and platform-independent.
Compact: a dense binary format for fast downloads.
Open and debuggable: a human-readable text format (WAT).
Wasm is not a replacement for JavaScript. It complements it: JS handles the DOM and glue code, and Wasm handles compute-heavy work and code reuse.
1.2 History
asm.js (a strict JS subset compiled by Emscripten) proves near-native web performance
WebAssembly announced by Mozilla, Google, Microsoft, and Apple MVP ships in all major browsers
WebAssembly 1.0 becomes a W3C Recommendation (the 4th web language, after HTML, CSS, and JS). WASI announced.
Bulk memory, reference types, multi-value, SIMD, threads, and BigInt integration ship
WebAssembly 2.0 drafts. Component Model progress.
WasmGC, tail calls, exception handling ship in browsers. WASI 0.2 (Preview 2) with the Component Model released.
WebAssembly 3.0 completed (GC, memory64, multiple memories, exnref exceptions, typed function refs, relaxed SIMD, tail calls, deterministic profile, JS string builtins). WASI 0.3 (native async) previews.
1.3 Where Wasm Runs
Browsers: Chrome/Edge (V8), Firefox (SpiderMonkey), Safari (JavaScriptCore).
JS runtimes: Node.js, Deno, Bun.
Standalone runtimes: Wasmtime, Wasmer, WasmEdge, WAMR, wazero, wasm3.
Edge/serverless: Cloudflare Workers, Fastly Compute, Fermyon/Spin, Vercel/Netlify edge functions, Akamai, Shopify Functions.
Embedded/IoT, blockchains (smart contracts: CosmWasm, Polkadot, NEAR), plugin hosts (Envoy, Zellij, Figma plugins, databases), containers/Kubernetes (runwasi, SpinKube).
1.4 Famous Wasm Applications
Figma (C++ rendering engine), Adobe Photoshop/Lightroom on the web, AutoCAD Web, Google Earth, Google Sheets (WasmGC calculation engine), Squoosh (image codecs), ffmpeg.wasm, SQLite Wasm, DuckDB-Wasm, Pyodide (Python in the browser), Unity/Godot web exports, TensorFlow.js/ONNX Runtime Web backends, Zoom web client (codecs), 1Password, Microsoft Flight Simulator cloud tools, Amazon Prime Video UI.
1.5 When to Use Wasm (and When Not To)
CPU-intensive work: codecs, compression, crypto, physics, image/video/audio processing
Simple DOM manipulation, typical CRUD UIs Porting existing C/C++/Rust libraries to the web
Code dominated by JS↔Wasm boundary calls Games and emulators Small scripts where JS is fast enough
Portable, sandboxed plugins and extensions Anything needing heavy direct DOM access (unless using a Wasm UI framework)
Server-side/edge functions with fast cold starts When you need a mature debugging experience for every language
Deterministic, language-agnostic execution