WebAssembly
WebAssembly (Wasm) is a binary instruction format for a stack-based virtual machine, designed as a portable compilation target for programming languages. It enables deployment of applications on the web for both clients and servers. Developed as an open standard by the W3C with participation from all major browsers, WebAssembly aims to execute code at near-native speed while being secure, portable, and interoperable with JavaScript.
Key Features
Near-Native Performance
- Binary format executes significantly faster than JavaScript for compute-intensive tasks
- Compiled ahead of time, avoiding JIT compilation overhead for critical paths
- Designed for predictable, consistent performance
Language Agnostic
WebAssembly can be targeted by multiple languages:
- Rust (via Rust and WebAssembly)
- C++
- C
- AssemblyScript (TypeScript subset)
- Go, Python, Java, and others
Security
- Runs in a sandboxed execution environment
- Memory-safe by design with linear memory model
- No direct access to the host system without explicit imports
Portability
- Supported by all major browsers (Chrome, Firefox, Safari, Edge)
- Runs outside browsers via runtimes like Wasmtime, Wasmer, and WasmEdge
- Same binary runs across different platforms and architectures
JavaScript Interoperability
- Seamless integration with JavaScript APIs
- Can call JavaScript functions and be called from JavaScript
- Shares memory with JavaScript when needed
Use Cases
- Gaming: High-performance game engines running in the browser (e.g., Unity, Unreal Engine web exports)
- Image & Video Processing: Real-time filters, encoding/decoding, and editing
- Scientific Simulations: Physics engines, data visualization, computational models
- Augmented/Virtual Reality: WebXR applications with demanding computation
- Cryptography: Efficient crypto operations in web applications
- Edge Computing: Lightweight, portable workloads on edge servers (via WASI)
- Plugin Systems: Sandboxed, portable plugins for applications
WebAssembly System Interface (WASI)
WASI extends WebAssembly beyond the browser, providing a standardized system interface for file access, networking, and other OS capabilities. It enables Wasm modules to run as portable server-side applications, making WebAssembly a compelling target for cloud and edge computing.
Tooling Ecosystem
- wasm-pack - Build and package Rust-generated Wasm
- Emscripten - C/C++ to WebAssembly compiler toolchain
- Wasmtime - Standalone Wasm runtime
- Wasmer - Universal Wasm runtime
Related Concepts
- Rust - Leading language for WebAssembly development
- Rust and WebAssembly - Rust’s Wasm integration
- C++ - Traditional systems language compiling to Wasm
- AssemblyScript - TypeScript-like language targeting Wasm
- JavaScript - WebAssembly’s host environment on the web