CompilerGray product news

Gray native loops reach 25.918× VM speedup

The same 100-million-iteration sum ran in a 210.511 ms median with native lowering and 5,456.099 ms with the Gray JIT disabled.

Workload100M typed iterations
Native median210.511 ms
VM median5,456.099 ms
Median speedup25.918×
01

Native loops now preserve Gray semantics

Gray’s x86-64 backend can lower typed loops, local mutation, integer comparisons and control flow into machine code through the documented native runtime ABI. Unsupported functions continue through verified VM fallback.

The backend does not accept a loop merely because it can encode a backward branch. Every generated backedge calls the runtime’s stop-token safepoint and returns a structured cancellation exit when work should stop.

That contract keeps native execution inside Gray’s structured task model. A hot loop can lose bytecode dispatch without becoming an uninterruptible island inside the process.

02

The same loop ran 25.918 times faster

The diagnostic computed an identical 100-million-iteration integer sum in fresh, CPU-pinned Gray processes. One policy enabled native lowering; the other disabled the JIT and executed the same function through the VM.

Seven accepted samples produced a 210.511 ms native median and a 5,456.099 ms VM median. Dividing those medians yields a 25.918× end-to-end improvement for this workload.

The measurement includes a stop-token safepoint on every loop backedge. The reported gain therefore includes the cost of retaining cancellation rather than benchmarking an unsafe stripped-down loop.

03

Cancellation is part of the differential

A dedicated test starts a typed loop with a nine-quintillion-iteration ceiling, waits 20 milliseconds, requests cancellation and requires a CancelledError. The test passes with native lowering enabled and with interpreter-only execution.

Live JIT, Live VM, Static JIT and Static VM produce the same result. ASan and UBSan builds exercise native relocation, generated frames, structured exits and the spawned-loop cancellation path.

The runtime ABI identifies exit kind, ABI version, source function and instruction. Native calls therefore preserve source-located errors and cancellation identity as execution returns to the VM.

04

The benchmark marks backend progress

This is a Gray-native-versus-Gray-VM diagnostic. It does not compare Gray with C++, Rust, Go or another compiler, and it does not claim that every Gray application becomes 25.918 times faster.

The result demonstrates that VM dispatch was the dominant cost in an eligible sustained loop and that Gray’s backend can remove it without changing the cancellation contract.

Broader value lowering, more native call paths and additional platform backends remain active compiler work. Each expansion keeps the same differential rule: native execution must match the VM before its speed is accepted.