v149 · WebAssembly · WasmGC

Method Dispatch Bench

Compare three ways to expose WasmGC struct behaviour to JavaScript: a raw JS wrapper class that duplicates logic, a per-object closure approach, and the custom descriptor pattern where the prototype is the WasmGC struct itself.

WasmGC custom descriptors require Chrome 149+ with the WasmGC flag enabled. This demo benchmarks JavaScript approximations of the three patterns so you can see the memory and dispatch trade-offs in any browser.
1 000 000
pattern A: JS wrapper class
method dispatch via JS prototype chain
pattern B: per-object closures
method stored on each instance
pattern C: custom descriptor (simulated)
WasmGC struct as prototype host

Click "Run benchmark" to start.

Run the benchmark to see which pattern wins and why.

the three patterns explained

// Pattern A: JS wrapper class wraps every Wasm struct call
class WasmPoint {
  constructor(wasmStruct) { this._s = wasmStruct; }
  distanceTo(other) {
    return Math.hypot(this._s.x - other._s.x, this._s.y - other._s.y);
  }
}

// Pattern B: closure stored per instance (memory heavy)
function makePoint(wasmStruct) {
  return {
    distanceTo(other) {
      return Math.hypot(wasmStruct.x - other.x, wasmStruct.y - other.y);
    }
  };
}

// Pattern C: custom descriptor — Wasm struct IS the object
// (WasmGC struct with a custom descriptor pointing to a JS prototype)
// wasmPoint.distanceTo(other)  // direct, no wrapper
// Methods live on the prototype, shared across all instances

see also

implementation reference

Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗