<!-- https://tinyscript.tinyactors.dev/compare/quickjs-wasi/ -->
# tinyscript and quickjs-wasi · Compare

Kind: explanation. For: [Embedder](https://tinyscript.tinyactors.dev/audiences/embedder.xml), [Agent builder](https://tinyscript.tinyactors.dev/audiences/agent-builder.xml), [Platform builder](https://tinyscript.tinyactors.dev/audiences/platform.xml).
Voice: [Dario](https://tinyscript.tinyactors.dev/voices/explanation.xml).

> How tinyscript compares with quickjs-wasi, Vercel's snapshotable QuickJS-ng in WebAssembly: language, sandboxing, snapshots and bounding a call.

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 verdict](https://tinyscript.tinyactors.dev/compare/quickjs-wasi/index.md#choose) · [Compare every engine](https://tinyscript.tinyactors.dev/compare/index.md)

<a id="what"></a>

## 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](https://github.com/vercel-labs/quickjs-wasi/blob/main/README.md)
- **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](https://github.com/vercel-labs/quickjs-wasi/blob/main/README.md)

<a id="differences"></a>

## 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.

| Question | quickjs-wasi | tinyscript |
|---|---|---|
| Language | QuickJS-ng, scripts only | 62.9% of test262 in strict mode |
| Bounding a call | An interrupt that throws | Exact fuel; the call continues |
| Saving a run | Whole-VM snapshots between calls | Sessions saved as their values |
| Boundary | One WebAssembly instance per VM | A message interface in your process |

- **Clamp a retry deadline with Math.min/max**: tinyscript, 66.7% fewer than QuickJS
- **Numeric loop with a helper**: tinyscript, 53.3% fewer than QuickJS
- **Branching reconnect policy**: tinyscript, 32.5% fewer than QuickJS
- **Fold delivered byte counts across telemetry batches**: tinyscript, 0.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](https://github.com/tinyactors-dev/tinyactors/blob/ef90baf70d8974072e9007c482190ec61043ce7c/tinyscript/bench/RESULTS.md).

<a id="choose"></a>

## Which one to choose

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

- **Use quickjs-wasi when**: you need broad language coverage in a JavaScript or TypeScript host today, and snapshots between calls are enough.
- **Use tinyscript when**: calls 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-wasi](https://github.com/vercel-labs/quickjs-wasi) · [Compare every engine](https://tinyscript.tinyactors.dev/compare/index.md)
