Start with a function you already have.
-
Install
npm install jz -
Compile a function
import jz from 'jz' const { exports } = jz` export const dist = (x, y) => (x*x + y*y) ** 0.5 ` console.log(exports.dist(3, 4)) // 5 -
Pass whole arrays
import jz from 'jz' const { exports, memory } = jz` export const sum = a => { let total = 0 for (const x of a) total += x return total } ` const values = new Float64Array([1, 2, 3]) console.log(exports.sum(values)) // 6 memory.reset()Value Crosses number directly string, array, typed array copied plain object by reference memory.Float64Array(n)shared, no copy heap allocations freed on return or by memory.reset() -
Ship the
.wasmnpx jz kernel.js # → kernel.wasm npx jz kernel.js -O3 # fastest; -Os smallest npx jz kernel.js --host wasi # standalone WASI module npx jz kernel.js --why # what kept a loop scalarimport { instantiate } from 'jz/interop' // 19 kB gzip const wasm = await fetch('kernel.wasm').then(r => r.arrayBuffer()) const { exports } = instantiate(wasm) -
Check both
Tests run them against kernel.jsandkernel.wasmSpeed time the whole call, transfer included Scalar loops --whynames the operation that blocked SIMD
What compiles
| Supported | Not supported |
|---|---|
| classes, closures, generators, async/await | eval, Function, with |
| destructuring, spread, 64-bit BigInt | Proxy, Reflect, prototype chains |
| typed arrays, Map, Set, JSON, RegExp, Date | top-level await, computed import() |
| timers, Web codecs, ES modules | DOM, Node modules, Intl, Temporal |
No GC, ASCII case, UTC dates: where it differs from JS.