AOT without a second compiler
We built a closed-world JavaScript-to-native compiler, measured it, and threw it away. Quench's ahead-of-time mode is the interpreter specialized to what is known at build time, and this is why.
Ahead-of-time compilation for JavaScript is an old wish: hand the tool a program, get back one native executable that starts instantly and needs no runtime installed. Quench has a mode for it.
$ quench --build-aot app.ts -o app
$ ./app
This post is about the design behind that command, and the version of it we discarded on 7 November 2026.
The prototype we threw away
The first AOT design was a separate closed-world compiler. It read the whole program, assumed nothing could change at run time, and translated JavaScript to native code through its own lowering, independent of the interpreter and the JIT.
It worked, and it ran Richards at a score of 5,846. That was slower than our own JIT on the same program.
The reason was not subtle. The prototype knew the whole program but not the things that make code fast: which numbers are integers, what shape each object has, which function a call reaches. Numbers stayed boxed. Without those facts, "compiled" just means the interpreter's work unrolled into a longer listing.
And it was a second implementation of JavaScript semantics. Every language feature would need to be written, tested and kept in sync twice.
The reversal
So we reversed the design. There is no separate AOT compiler in Quench.
The whole-program knowledge that the prototype had is still used. It just becomes an input to the specializer:
- Callee identity. If only one function in the program is ever stored under a property name, a call through that name can bind to it.
- Build-time shapes. Object layouts that are fixed by the program text are known before it runs.
- Unboxed integer fields. A field only ever assigned integers can be stored as one.
TypeScript types belong on that list too. Quench parses TypeScript natively and keeps the types instead of erasing them, and the design is for them to drive specialization: a declared type picks the specialized code up front, and is checked once where a value enters typed code, since a cast or an any can make a declaration wrong at run time. After that one check the type is relied on like any other proven fact. This is being built out now.
What happens to eval
A closed-world compiler has to refuse eval and new Function. Quench does not refuse them. The rule is static: if the program can reach eval or Function, the interpreter is linked into the executable, and dynamic code runs through it. If it cannot, the interpreter is left out.
Guards work the same way. In the JIT, a failed guard deoptimizes back to the interpreter. In an AOT image, the cold side of a guard goes to a compiled generic path, so the program keeps running native code even when an assumption fails.
Where it stands
Honestly: it works and it is not fast yet.
link and pass with the source deleted
of 53,406 pass as AOT images
more than 5x the C equivalent
Correctness came first. Every one of the sixteen JavaScript and TypeScript benchmark programs builds to an executable that runs correctly with the source files deleted. Speed is behind: on 7 November, 36 of 46 primitive operations took more than five times the instructions of the equivalent C, and a few (spread and destructuring, string building) took hundreds of times more.
The goal is an executable where every function is compiled and the code is within five times of C. Because AOT is the same specializer as the JIT, it does not have its own performance work. Every improvement to how the interpreter's operations specialize shows up in both. That was the point of the reversal.
Why this is the right shape
A second compiler is two sets of bugs and two sets of performance work, forever. One specializer with two fact sources means:
- Identical behavior by construction. There is one definition of what
a + bmeans. - AOT inherits every JIT improvement and the other way round.
- The fallback is always there. Anything the specializer cannot prove still runs, through the same generic operation the interpreter uses.
The next post in this series covers the mechanism that makes "one definition" possible.