The Complete Guide to the Universal Compilation Target
- About This Book
Introduction: The Problem That WebAssembly Solves
Chapter 1: The Problem WebAssembly Solves
- The Plugin Era and Its Failures: A Cautionary Tale
- The asm.js Experiment: A Clever Workaround
- The Design Principles Behind WebAssembly
- What WebAssembly Is (and Isn’t)
- The Design Principles in Practice
Chapter 2: A Brief History of WebAssembly
- The Precursors: asm.js and Google Native Client
- The Proposal and Formation of the Community Group: A Cross-Company Collaboration
- First Releases and Browser Adoption
- Feature Milestones and the Evolution of the Spec
- The Road to Standardization and Beyond
- Key Dates and Milestones
- Chapter Summary
- Exercises
Chapter 3: Architecture and Design
- The Binary Format: Module Structure
- The Stack-Based Virtual Machine: Design Trade-Offs
- The Stack-Based Virtual Machine
- Linear Memory and Tables: Architecture and Layout
- Types and Value Semantics: A Deeper Look
- Modules, Imports, and Exports: The Building Blocks
- Design Decisions That Shaped the VM
- Types and Value Semantics
- Modules, Imports, and Exports: The Building Blocks
- Design Decisions That Shaped the VM
- Chapter Summary
- Exercises
Chapter 4: Compilation Toolchains
- LLVM and the WebAssembly Backend: The Engine of Compilation
- Emscripten: The C/C++ to WebAssembly Compiler Toolchain
- Rust and the WebAssembly Target
- Go and TinyGo: Compiling Go to WebAssembly
- .NET and Blazor: Running C# in the Browser
- AssemblyScript and TypeScript-Based Languages
- Other Language Runtimes
- The Compilation Pipeline: From Source to .wasm
- Toolchain Selection Guide
- Chapter Summary
- Exercises
Chapter 5: Runtime Environments and Execution
- Browser Engines and WebAssembly: A Deep Dive
- JIT Compilation Phases: Step-by-Step Execution
- Memory Allocation in Browsers: A Deeper Look
- JIT Compilation Phases: From Binary to Machine Code
- Memory Allocation in Browsers
- Standalone Runtimes: Wasmtime, Wasmer, Wazero, and More
- Performance Characteristics: Startup, Memory, Throughput
- Debugging WebAssembly
- Chapter Summary
- Exercises
Chapter 6: Security Model and Sandboxing
- The Sandbox Model: No Direct OS Access
- Memory Safety: Bounds Checking and Linear Memory
- Type Safety and Control Flow Integrity
- Capabilities and the Import/Export Model
- Web Platform Permissions: Permissions Policy and Wasm Fetch
- Security Comparisons: Wasm vs. JavaScript, Wasm vs. Native
- Side-Channel Risks and Known Vulnerabilities
- Emerging Defenses: Cage and Hardware Acceleration
- Security Best Practices for Wasm Developers
- Chapter Summary
- Exercises
Chapter 7: JavaScript Interoperability
- The JS API: Core Constructs and Their Lifecycle
- Calling Wasm from JavaScript and JavaScript from Wasm
- Data Passing: Numbers, Strings, and Structured Data
- Callbacks and Function References
- Performance of the JS/Wasm Bridge
- Interface Types: Bridging the Type Gap
- Component Model: The Future of Cross-Language Interop
- Practical Interoperability Patterns
- Chapter Summary
- Exercises
Chapter 8: Advanced WebAssembly Features
- SIMD: Single-Instruction Multiple-Data Extensions
- Threads and Atomics: Shared Memory Concurrency
- Garbage Collection: Managed Memory in Wasm
- Tail Calls and Recursion Optimization
- Exception Handling in Wasm
- Multi-Memory and Beyond
- The State of Advanced Features in 2026
- Chapter Summary
- Exercises
Chapter 9: WASI and Non-Browser Runtimes
- The Design Goals of WebAssembly System Interface: Extending Wasm Beyond the Browser
- WASI Versions: From Preview 1 to Preview 2 (WASI 0.2)
- Filesystem Access and Path Handling: The Capability Model in Detail
- Networking, Environment Variables, and Randomness: The WASI Preview 2 Expansion
- Networking, Environment Variables, and Randomness
- Serverless Runtimes: Cloudflare Workers, Deno, Fastly
- Edge Computing and WebAssembly
- Embedded Systems and IoT with TinyGo and Wasmtime
- The Non-Browser Ecosystem: A Growing Landscape
- Security in Non-Browser Environments
- Deployment Patterns for Non-Browser Wasm
- Chapter Summary
- Exercises
Chapter 10: The Component Model
- The Problem with the Current Module Model: Why We Need Components
- The Evolution of WASI: From Explicit Imports to Declarative Worlds
- Interface Types: Typed Function Signatures Across Languages
- Component Model Architecture: How Adaptation Layers Work
- WIT (WebAssembly Interface Type): The IDL for Components
- wit-bindgen: Language Binding Generation in Practice
- Component Model Architecture: Components, Instances, and Adaptation
- WIT (WebAssembly Interface Type): The IDL for Components
- wit-bindgen: Language Binding Generation
- Polyfill Implementations and Interop Layers
- Cross-Language Composition and Plugin Systems
- The Road to Component Model 1.0
- Practical Component Model Development
- Chapter Summary
- Exercises
Chapter 11: Real-World Applications and Case Studies
- Gaming: Godot, Defold, and Browser-Based AAA: The Performance Frontier
- Creative Tools: Figma, Photopea, and Image Processing: Desktop-Class Apps in the Browser
- Creative Tools: Figma, Photopea, and Image Processing
- AI and ML Inference: On-Device Intelligence
- Database and Storage: SQLite in Wasm
- Enterprise and DevOps: Podman, Kubernetes Tools, and Container Management
- Multimedia: FFmpeg, Video Processing, and Audio DSP
- Performance Benchmarks: Wasm vs. JavaScript Across Workloads
- The Adoption Curve: Numbers That Matter
- Chapter Summary
- Exercises
Chapter 12: Production Practices and Best Practices
- Building and Optimizing: LTO, Size Optimization, and Debug Info
- Testing Strategies: Unit Tests, Integration Tests, and Fuzzing
- Deployment Strategies: CDN Delivery, Caching, and Versioning
- Monitoring and Observability
- CI/CD Pipelines for Wasm Projects
- Common Pitfalls and How to Avoid Them
- Best Practices Summary
- Looking Forward: Continuous Improvement
- Chapter Summary
- Exercises
Conclusion: The Future of Portable Compute
- Where the Spec Is Heading
- The Server-Side Revolution
- AI and Wasm: Inference at the Edge
- The Vision: A Universal Compilation Target and Composition Format
- What Could Go Wrong: Fragmentation, Complexity, and Adoption Barriers
- What Could Go Wrong: Fragmentation, Complexity, and Adoption Barriers
- Delivering on the Promise
- The Road Ahead