Build Modes
Voltaire provides two WASM build modes optimized for different use cases:ReleaseSmall (Production)
Size-optimized build for production bundles: Characteristics:- Minimal bundle size (~50-100KB compressed)
- Aggressive dead code elimination
- Optimized for download speed
- Suitable for web applications
ReleaseFast (Performance)
Performance-optimized build for compute-intensive workloads: Characteristics:- Maximum execution speed
- Larger binary size (~150-300KB compressed)
- Loop unrolling and inlining
- Suitable for backend services, workers
Performance Comparison
- Encoding
- Decoding
- Selector Matching
Encoding function call with parameters:Results (1M iterations):
- Pure JS: ~850ms
- WASM (ReleaseSmall): ~320ms (2.6x faster)
- WASM (ReleaseFast): ~180ms (4.7x faster)
Usage
Automatic Selection
Voltaire automatically uses WASM when available:Manual Loading
For advanced control, manually load WASM module:- Node.js
- Browser
- Worker
Checking WASM Status
Verify if WASM is loaded:Memory Management
WASM module manages its own memory efficiently:Linear Memory
WASM uses linear memory for all operations:- Initial: 16 pages (1MB)
- Maximum: 256 pages (16MB)
- Growth: Automatic on demand
Allocation Strategy
Zig’s allocator optimizes for CallData operations:- Minimal fragmentation
- Batch deallocation
- Zero-cost cleanup
Memory Limits
Set memory limits for safety:Bundle Optimization
Tree-Shaking
Use tree-shakeable imports to minimize bundle size:Lazy Loading
Load WASM on demand to reduce initial bundle:Code Splitting
Split WASM by route/feature:Platform Support
Compatibility
WASM module works across platforms:| Platform | Support | Notes |
|---|---|---|
| Chrome 57+ | ✅ Full | Native WASM support |
| Firefox 52+ | ✅ Full | Native WASM support |
| Safari 11+ | ✅ Full | Native WASM support |
| Edge 16+ | ✅ Full | Native WASM support |
| Node.js 12+ | ✅ Full | Built-in WASM runtime |
| Deno | ✅ Full | Native WASM support |
| Bun | ✅ Full | Optimized WASM JIT |
Fallback
Automatic fallback to pure JS when WASM unavailable:Benchmarking
Write benchmarks to verify performance in your environment:Debugging WASM
Enable Debug Logging
Inspect Module
Production Recommendations
- Use ReleaseSmall for web apps - Minimize download time
- Use ReleaseFast for compute - Backend services, workers
- Lazy load WASM - Don’t block initial page load
- Monitor memory - Set limits for long-running processes
- Test fallback - Ensure JS path works without WASM
See Also
- Fundamentals - CallData basics
- Usage Patterns - Common patterns
- Encoding - ABI encoding details

