The host owns the buffers
A host request is written into a packet buffer the host supplies, and the host answers it with a reply.
Source:tinyscript, include/tinyscript.h, ta_tinyscript_set_host_buffers
QuickJS is great, and I tried hard to just use it. This page is about the four jobs where it kept getting in the way, and the engine we built for them instead.
Writing a JavaScript interpreter is easy; writing one that is faster than QuickJS is not.
QuickJS, especially as quickjs-ng and quickjs-wasi, is small, complete and quick to start. Point a coding agent at building an interpreter with naive instructions and you find out fast: QuickJS is really hard to beat on speed.
So tinyscript is measured against QuickJS on every change. Callgrind counts the instructions both engines retire on the same programs, with the same output required.
Some requirements can't be bolted onto an engine afterwards; they decide its design.
Our actor runtime needed all four at once. So does an agent running code mode, and so does a platform that runs its customers' plugins on every request.
On a server, every usual way to run untrusted JavaScript trades away one of the four.
| Option | What it costs |
|---|---|
| QuickJS in WebAssembly | A second engine around the first, to make it a sandbox. |
| V8 isolates | Too heavy for one per session, and not a security boundary alone. |
| Ahead-of-time compilers such as scriptc | Native programs, not code you can safely run in your process. |
tinyscript aims at all four jobs, inside your process. The comparison also covers djs and Psychoscript, which aim at code mode too.
A sandbox that filters a script's files and sockets is only as safe as its filter.
So tinyscript has nothing to filter. All it asks of your program is a buffer of bytes, and it does all of its work in there.
When a script needs the outside world, it writes a message into another buffer and your program writes the answer back. Because everything is deterministic, you can save a session, restore it later, or inspect everything it holds.
A host request is written into a packet buffer the host supplies, and the host answers it with a reply.
Source:tinyscript, include/tinyscript.h, ta_tinyscript_set_host_buffers
An engine that runs each script to completion makes every session wait for the slowest one, and an endless loop waits forever.
tinyscript runs a call for the fuel you give it, then returns to your program. You continue the call exactly where it stopped, or abandon it, so a session that isn't running takes no time at all.
One compiled program runs in many realms, each with its own globals and heap. Between calls, a realm's stacks hold nothing live.
ta_tinyscript_run runs a call for at most the fuel it is given, and the next run continues where it stopped.
Parsing the same plugin on every request spends most of the request before the plugin runs.
tinyscript compiles to bytecode once and runs that bytecode through its VM. TypeScript annotations are hints for that compiler; it doesn't check types and never will, because tsc does that well.
QuickJS was born in a world without WebAssembly. Now WebAssembly is everywhere, even where you don't see it, so we made it tinyscript's bytecode.
That paves the way for whole-program compilation: JavaScript or TypeScript in, one WebAssembly module of your whole program out. Node.js, Bun, a browser or any WebAssembly runtime then compiles it to native code.
A pure numeric module instantiates with new WebAssembly.Instance(module) in a standard engine.
Source:tinyscript, README.md
Depending on an engine means knowing exactly what runs today.
tinyscript is an early alpha: APIs will change, and its internals are not a contract. It runs every source as strict code, so with is always an error.
Here is the honest number: the share of test262, the ECMAScript conformance suite, that passes today. It goes up with almost every commit.