Skip to main content
CallData operations can be accelerated using WebAssembly for performance-critical applications. The Zig implementation compiles to WASM, providing near-native speed in browser and Node.js environments.

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 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:
No code changes needed - WASM acceleration is transparent.

Manual Loading

For advanced control, manually load WASM module:

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:
Memory grows automatically when needed:
  • Initial: 16 pages (1MB)
  • Maximum: 256 pages (16MB)
  • Growth: Automatic on demand

Allocation Strategy

Zig’s allocator optimizes for CallData operations:
Benefits:
  • 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:

Fallback

Automatic fallback to pure JS when WASM unavailable:
No polyfills or configuration needed.

Benchmarking

Write benchmarks to verify performance in your environment:

Debugging WASM

Enable Debug Logging

Inspect Module

Production Recommendations

  1. Use ReleaseSmall for web apps - Minimize download time
  2. Use ReleaseFast for compute - Backend services, workers
  3. Lazy load WASM - Don’t block initial page load
  4. Monitor memory - Set limits for long-running processes
  5. Test fallback - Ensure JS path works without WASM

See Also