kkrpc — WASM Boundary Layer#

Typed bidirectional RPC for JS/TS ↔ WASM communication.

Role#

kkrpc is the typed boundary layer between JavaScript and WASM modules. Same API, transport swapped per target:

TargetTransport
BrowserSharedWorker (one WASM shared across tabs)
Native webviewsWeb Worker
CF WorkersDirect call (same isolate)
Bare metalstdio (Node/Bun/Deno)

WASM Compilation Strategy#

Two builds, not three:

BuildTargetUsed By
wasm32-unknown-unknownBrowser + CF Workerswasm-bindgen
wasm32-wasip1Bare metalWASI runtime

Key Principles#

  • Thin boundary: Coarse operations, not fine-grained calls
  • Typed arrays: For bulk data transfer (mesh vertices, etc.)
  • Lazy init: WASM modules initialized on first use
  • Zero-copy: Where possible, share memory instead of copying

CF Workers Limits#

Design to these constraints:

  • 3 MB compressed WASM
  • 128 MB memory
  • 1s startup time

References#