Quench.
C PARITYKERNELS

blog / · 4 min read · performance

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.

CPU time relative to clang -O2 (log scale, 1 = same as C), 14 November 2026interpreterb-jitu-jitFloat64Array sum35x49x4.3xcrc324.4x5.4x1.2xdot product66x87x4.9xmatmul 12852x62x3.7xfib(30)22x151x9.5xquicksort14x13x8.8xstruct objects92x79x14xnbody78x68x70x
u-jit is the optimizing tier on Cranelift, b-jit the copy-and-patch tier. One machine, wall-clock CPU time. Lower is better.

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 staticallyJavaScript must prove
the type of every variablethat a register holds a double, and keeps holding one
the layout of a structthat an object has a shape, and nothing changed it
the length of an arraythat an index is in bounds, once per loop and not per access
which function a call reachesthat a property still names the same function
that nothing interrupts a loopwhere the collector may run, and what is live there
that locals live in registersthat 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.

Targets for compiled code, instructions per iterationsum6dot8matmul10fib (per call)25structs30crc35nbody (per pair)40
Milestone targets set on 15 November 2026. On that day the measured ceilings were sum 7, dot 9, matmul 12, crc 45, nbody 276 and structs 349.

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.

Try it

Quench builds from source with Cargo and runs TypeScript, JavaScript and WebAssembly.

Build and run

Work on it

Interpreter, JIT, AOT, GC, Node APIs. Every claim on this blog has a measurement you can rerun.

Where to start

Follow it

New posts land here as the engine moves. Star the repository or subscribe to the feed.

Star on GitHub Feed