demo · v130
Wasm JS String Builtins benchmark
Instantiate two real Wasm modules — one using imported wasm:js-string built-ins, one calling back into JS — and benchmark a string-heavy loop. The first should be measurably faster because the calls inline.
JS-callback (slow path)
—
ms
wasm:js-string (fast path)
—
ms
speedup
—
× faster
the code
// Wasm module declares an import against "wasm:js-string":
(module
(import "wasm:js-string" "length" (func $len (param externref) (result i32)))
(import "wasm:js-string" "charCodeAt"
(func $cca (param externref i32) (result i32)))
(func (export "sum") (param $s externref) (result i32)
;; sum char codes — calls inline into native string ops
…))
// JS side passes { builtins: ["js-string"] } at compile time:
const mod = await WebAssembly.compileStreaming(fetch("m.wasm"),
{ builtins: ["js-string"] });