ReviewOS

zig-utils/zig-js

perf(json): avoid general float conversion for exact short integers

#992
Closed glennmichael123 opened this 10 days ago ·
10 days ago

Parent: #473. Reproduced at d74ac11, after #991, with the real CI-pinned collector and Zig 0.17.0-dev.1770 Debug. A 4096-field integer array parsed 512 times returns checksum 126423945728; the initial diagnostic retires 9,829,616,059 instructions. A separate 4096-iteration sampled run completes with checksum 1011391565824. The dominant parseNumber-to-parseFloat stack accounts for 730 of 1782 main-thread samples. This is a CPU-work diagnostic, not a production-throughput claim.

Proposed boundary: after the existing JSON grammar scan, convert integer-only tokens of at most 15 decimal digits through u64 and one exact f64 conversion. Preserve signed zero; retain the correctly rounded generic converter for longer integers, decimals and exponents.

Done requires bit-exact boundary/random differential tests, grammar and reviver-source tests, Node and tree/VM probes, unchanged JSON corpus outcomes, before/after integer and decimal controls, a separate main commit, and checked-in raw evidence linked here. No benchmark/JSC scorecard promotion from Debug diagnostics.

10 days ago

The independently tested implementation is pushed to main in 0474640. It retains the general correctly rounded converter outside the exact short-integer domain. Five focused direct-root tests pass, including 4096 seeded signed bitwise comparisons and boundary cases. JSON test262 remains 165 pass / 0 fail with 165 tree/VM agreements and zero divergences; numeric grammar, signed-zero and reviver-source fixtures pass both tiers before and after. Integer/decimal probes are checked in under bench/. Collecting seven alternating pairs from the clean commit; evidence publication will close this child, not the broad parent #473.

10 days ago

Completed in 0474640; evidence pushed in 200b87f. Seven alternating exact-parent pairs show 27.5% fewer retired instructions for the integer-array probe; fractional controls cost 0.41% more and remain visible. Report: https://github.com/zig-utils/zig-js/blob/main/docs/.data/json-parse-cpu-work-2026-09-29.md ; raw samples: https://github.com/zig-utils/zig-js/blob/main/docs/.data/json-parse-cpu-work-2026-09-29.json . Bit-exact boundaries, 4096 seeded signed conversions, invalid grammar, negative zero and reviver source pass; JSON remains 165 pass / 0 fail and 165 tree/VM agreements. Default-arena Debug CPU work only, not runtime-GC/ReleaseFast/JSC throughput. Parent #473 remains open; #991 is the separately landed escaped-string fix.

Sign in to comment on this issue.