JavaScript that looks like C should cost what C costs
We wrote eight small kernels twice, once in JavaScript and once in C, and counted. The results set the standard Quench's compiled code is now held to, and showed one benchmark that had never been compiled at all.
A lot of JavaScript is not very dynamic. A loop that sums a Float64Array, a CRC over bytes, a matrix multiply: the types never change, the arrays have fixed length, the calls go to one known function. A C compiler given the same loop produces a handful of instructions per iteration.
On 14 November 2026 we made that the standard for Quench's compiled code:
Then we measured how far away we were.
Eight kernels, written twice
Each kernel exists as a JavaScript file and a C file doing the same work, with a checksum that must match.
Three things stand out.
The optimizing tier can get close. On the typed-array kernels u-jit was within 1.2 to 4.9 times of C. CRC32 at 1.2 times is essentially the same loop.
The baseline tier was slower than the interpreter. b-jit lost to the interpreter on five of eight kernels, and on recursive fib it was 151 times C against the interpreter's 22. A baseline JIT that loses to the interpreter is negative work. The cause was that any operation without a native template became a round trip into the interpreter, at 600 to 1,000 instructions each. Later posts cover it.
nbody was never compiled. Look at the last row: 78, 68, 70. The optimizing tier took the same time as the interpreter, because it was running the interpreter. The compiler rejected nbody's loops and nothing reported it.
What C knows that JavaScript must prove
The gap is not about the code generator. Our reading is that the gap is information.
| C knows statically | JavaScript must prove |
|---|---|
| the type of every variable | that a register holds a double, and keeps holding one |
| the layout of a struct | that an object has a shape, and nothing changed it |
| the length of an array | that an index is in bounds, once per loop and not per access |
| which function a call reaches | that a property still names the same function |
| that nothing interrupts a loop | where the collector may run, and what is live there |
| that locals live in registers | that no one can observe the frame |
Every row on the right is a fact that can be proved once and then relied on. Whenever the compiled code checks one of them again, on every iteration or every access, that is the distance from C.
Why nbody is the hard one
nbody is a small physics simulation: an array of body objects with position, velocity and mass, and a double loop computing pairwise forces. In C the inner loop is about 45 instructions per pair.
When we finally got it compiling, the first version ran 366 instructions per pair. The breakdown is a catalogue of unproved facts:
- The distance computation, a chain ending in a square root, was emitted six times, because the optimizer places a pure value at each use.
- Every double result was converted back to a canonical form and its tag re-tested, about 16 instructions, twice per pair.
- The loop counter was treated as a double.
- The shape of each array element was checked on every access.
- Loop state was spilled to the stack and reloaded around every call.
One of the loops was rejected outright for a reason that had nothing to do with the loop: the same register held an object early in the function and a number later. Facts were being tracked per register when they belong to a value.
The targets
Each kernel now has a ceiling in instructions per iteration, stored in the repository, that may only go down.
Sum, dot and matmul were already within one or two instructions of their targets. nbody and structs were seven and twelve times over. Those two are where objects meet numbers, and they are what most real JavaScript looks like.
What this standard changes
It changes what counts as done. "Faster than last week" is always available. "Within five times of the C a programmer would write" is a fixed external reference that does not move when we change our own baseline.
It also makes each remaining gap concrete. When nbody is at 276 instructions against a target of 40, the difference is a list of specific facts the compiler failed to keep. Each item on the list is a bug with a number attached.