tinyscript and quickjs-wasi

quickjs-wasi puts QuickJS-ng inside a WebAssembly sandbox and lets you snapshot it. It is what most people reach for when they want QuickJS on a server. Here is what that costs, and what tinyscript does instead.

Skip to the verdictCompare every engine

What quickjs-wasi does well

QuickJS on a server needs a sandbox around it, and wiring one up by hand is fiddly work.

quickjs-wasi, from Vercel Labs, compiles QuickJS-ng to a WASI reactor of about 1.4 MB and drives it from TypeScript in Node.js, Deno, Bun or a browser. Each VM is its own WebAssembly instance, with no shared memory between VMs.

Because all of the engine's state lives in linear memory, a snapshot is a copy of that memory, and a restore writes it into a fresh instance. That is a neat trick, and it works today.

The whole VM in a snapshot

A snapshot holds the runtime, context, all objects, the heap, atoms and pending promise jobs.

Source:quickjs-wasi, README

Deterministic when you override WASI

It does no implicit file or network I/O; overriding clock_time_get and random_get fixes Date.now(), Math.random and crypto.

Source:quickjs-wasi, README

Where tinyscript differs

Two engines in a row, a WebAssembly engine running an interpreter, pay twice for every instruction.

We built tinyscript so the sandbox is the engine itself: it only asks for a buffer and talks through messages, so nothing has to be wrapped around it. On native upstream QuickJS's own workloads, it retires fewer instructions on 17 of 18.

The trade is coverage. QuickJS-ng runs far more of the language than tinyscript does today, and quickjs-wasi runs anywhere WebAssembly does.

Questionquickjs-wasitinyscript
LanguageQuickJS-ng, scripts only62.9% of test262 in strict mode
Bounding a callAn interrupt that throwsExact fuel; the call continues
Saving a runWhole-VM snapshots between callsSessions saved as their values
BoundaryOne WebAssembly instance per VMA message interface in your process
  • tinyscript
  • QuickJS
  • QuickJS-ng
  • Clamp a retry deadline with Math.min/max66.7% fewer than QuickJS
  • Numeric loop with a helper53.3% fewer than QuickJS
  • Branching reconnect policy32.5% fewer than QuickJS
  • Fold delivered byte counts across telemetry batches0.1% more than QuickJS
Instructions retired, counted by Callgrind on native builds: shorter is better. quickjs-wasi runs QuickJS-ng inside a WebAssembly engine, which these counts do not include. From tinyscript's published results.

Which one to choose

Most readers need one answer: which engine to try first.

  • Use quickjs-wasi whenyou need broad language coverage in a JavaScript or TypeScript host today, and snapshots between calls are enough.
  • Use tinyscript whencalls must pause on fuel and continue, the same code runs many times, and you embed from C or want no WebAssembly engine around the interpreter.

Visit quickjs-wasiCompare every engine