{
  "id": "GW-2026-0004",
  "type": "report",
  "title": "Cancellation-Safe Native Loop Lowering in the Gray Runtime",
  "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.",
  "author": [
    {
      "family": "Proctor",
      "given": "Annabella",
      "ORCID": "https://orcid.org/0009-0000-0799-1757"
    }
  ],
  "publisher": "Grayworth Technical Publications",
  "issued": {
    "date-parts": [
      [
        2026,
        7,
        27
      ]
    ]
  },
  "version": "1.0",
  "DOI": "10.5281/zenodo.21633227",
  "URL": "https://grayworth.com/publications/gw-2026-0004",
  "keyword": "Gray; JIT compilation; x86-64; bytecode interpreter; native lowering; safepoint; cooperative cancellation",
  "publisher-place": "Sacramento, California, United States",
  "note": "Grayworth Publication ID GW-2026-0004. Related news record: https://grayworth.com/news/gray-native-loop-jit."
}
