WebAssembly (WASM)
WebAssembly is a safe, portable, low-level bytecode for running compiled languages (C/C++, Rust, etc.) in web browsers and other runtimes.
Overview
WebAssembly (WASM) provides a compilation target for native languages so applications can run inside browsers with near-native performance. Toolchains such as Emscripten compile C/C++ code into a WASM module plus a small JavaScript runtime glue layer.
How it Works
- Compile native source with an LLVM-based toolchain to produce a .wasm binary.
- A lightweight JavaScript glue layer loads the module, exposes runtime bindings, and maps browser APIs (e.g., WebGL, fetch, IndexedDB).
- Memory and system interfaces are mediated; file I/O is usually done via in-memory FS or network fetch/streaming.
Benefits
- Near-native performance for compute- and rendering-heavy code.
- Reuses existing C/C++ codebases and libraries (e.g., VTK) with minimal reimplementation.
- Runs cross-platform in modern browsers and in non-browser WASM runtimes that implement WASI.
Caveats & Limitations
- WASM modules are sandboxed: direct access to OS resources is limited and mediated by the host (browser or WASI).
- Binary size and initial download time can be significant for large C++ libraries; use optimization and code-splitting.
- Threading and GPU features vary by browser and toolchain; WebGL / WebGPU differences can affect rendering parity with native.
- I/O patterns should be adapted: use streaming, range requests, or server-side pre-processing for very large datasets.
VU-VERSE Usage
In VU-VERSE we compile VTK and the C++ rendering core to WASM (via Emscripten) so the same rendering pipeline can run in the browser. The QML UI runs using Qt for WebAssembly and communicates with the compiled core via the same bridge patterns used on desktop.
WASM ABIs: 32-bit vs 64-bit
WebAssembly currently defines both 32-bit (wasm32) and 64-bit (wasm64) ABIs; browser support and toolchain maturity differ. wasm32 is widely supported across browsers and toolchains (Emscripten, Qt for WASM), while wasm64 is experimental and not yet broadly available.
VU-VERSE currently targets wasm32 for production builds to ensure broad compatibility. Support for wasm64 (64-bit linear memory) is being evaluated for future builds where larger memory addressing is required.