Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

WebAssembly to JavaScript Bridge Myths

WebAssembly is designed to interoperate with the existing web ecosystem, but also embed in external systems outside the browser. Thus, WebAssembly does not natively operate directly on JavaScript data structures but instead operates on numbers passed into Wasm functions, or on its shared linear memory.

This means that JavaScript data that needs to be inspected by WebAssembly must be first copied into the linear memory. This fundamental truth has created some myths:

  1. Calling from Wasm to Js and vice-versa is expensive.
  2. Strings are expensive to pass across the Wasm bridge and ruin performance.
  3. Large complex objects are tricky to work with across the Wasm bridge.

The truth is the copy cost is unavoidable. How expensive is it, and can it be avoided or mitigated?