DeAI Research
Source · Zenodo (CERN European Organization for Nuclear Research)

Cancellation-Safe Native Loop Lowering in the Gray Runtime

2026Annabella Proctor

cid 486d5ac19dd209fdb67a0b9155aa7ef6afeabe89bcc3469ca3720470a8db1464 · original · open access · via openalex

Title: Cancellation-Safe Native Loop Lowering in the Gray Runtime
Authors: Annabella Proctor
Venue: Zenodo (CERN European Organization for Nuclear Research)
Year: 2026
Canonical: doi:10.5281/zenodo.21633226
URL: https://doi.org/10.5281/zenodo.21633226
Collector: openalex
OA: true

ABSTRACT
This paper evaluates bounded x86-64 native lowering for an eligible typed loop in the Gray language runtime. Historical profiling of Gray's sustained interpreter path recorded approximately 6.91 billion retired instructions and 1.60 billion branches with only 78,503 branch misses, indicating that dispatch and instruction volume, rather than branch-prediction failure, dominated the workload. The intervention lowers a supported loop to native code while preserving Gray's runtime ABI, source-function identity, structured exits, exact integer result, and cooperative cancellation. Seven interleaved, fresh-process, CPU-pinned measurements of a 100-million-iteration sum produced a native minimum, median, and maximum of 201.846, 210.511, and 259.657 ms. The same function with JIT disabled produced 5,336.574, 5,456.099, and 5,618.863 ms, yielding a 25.918x median end-to-end speedup. Both policies returned exactly 4,999,999,950,000,000. A separate 9-quintillion-iteration diagnostic requested cancellation after 20 ms and required CancelledError; Live JIT, Live VM, Static JIT, Static VM, AddressSanitizer, and UndefinedBehaviorSanitizer gates passed. The generated loop performs a stop-token safepoint at every backedge, so the measured native path includes the cooperative-interruption mechanism rather than benchmarking a semantics-stripped loop. The result demonstrates that Gray can remove the dominant bytecode-dispatch cost from an eligible hot region while retaining the runtime behavior needed for safe server operation.