# Web Assembly (WASM) A binary instruction format and compilation target that runs at near-native speed in web browsers and other host environments. Lets developers write performance-critical code in C, C++, Rust, Go, AssemblyScript, etc., and run it inside a sandboxed browser VM. The fourth official web language alongside HTML, CSS, and JavaScript. Spec: https://webassembly.org/ ## Why It Exists JavaScript is dynamically typed and JIT-compiled, fast but unpredictable. WASM is statically typed, AOT-compiled, and predictable — closer to native code performance with deterministic execution. Critical for compute-heavy workloads: 3D engines, image processing, ML inference, cryptography, simulations. ## Key Properties - **Portable**: runs in browsers, Node.js, Deno, Cloudflare Workers, edge runtimes - **Sandboxed**: capability-based security; no direct OS access - **Fast**: predictable performance, often within 1.5-2× native - **Language-agnostic**: any language with a WASM compiler - **Compact**: small binary size; designed for the network ## Role in Browser ML Before [[WebNN API]] and [[WebGPU]], WASM was the primary path for running ML inference in browsers: - [[ONNX Runtime Web]] ships a WASM backend for CPU inference - [[Transformers.js]] uses WASM to run quantized models entirely on CPU - TensorFlow.js has a WASM backend - llama.cpp has been compiled to WASM for in-browser LLM inference WASM remains the universal fallback when [[WebGPU]] or [[WebNN API]] aren't available. SIMD and threads extensions further close the gap to native performance. ## WASI WebAssembly System Interface — standard for running WASM outside browsers (servers, edge, embedded). Enables cross-platform binaries that work the same in browser and on the edge. ## References - https://webassembly.org/ - https://www.w3.org/groups/wg/wasm/ ## Related - [[WebGPU]] - [[WebNN API]] - [[ONNX Runtime Web]] - [[Transformers.js]] - [[On-Device Machine Learning]] - [[Edge Computing]] - [[WebAssembly System Interface (WASI)]]