Improve parseInt throughput for short numbers - #285
#285Improve parseInt throughput for short numbers#285trevorprater wants to merge 1 commit intobuger:masterbuger/jsonparser:masterfrom trevorprater:codex/parseint-short-fast-pathtrevorprater/jsonparser:codex/parseint-short-fast-pathCopy head branch name to clipboard
Conversation
|
@trevorprater — triaged your PR against the current Verdict: correct optimization, safe to merge with one carry-overCorrectness: ✅ Behaviorally identical to baseline across 15M fuzz iterations + a full edge-case sweep ( Performance: ✅ Real gain on the hot path — 22–37% faster on typical 1–10 digit integers (timestamps, IDs, counts), no allocations. One carry-over for our L3 posture: the fast path steals coverage from the slow path's final {in: "-9223372036854775807", out: -9223372036854775807}, // = -math.MaxInt64 — slow path, neg=TThis restores code-level MC/DC to 100% under #283's strict posture. RecommendationTwo options:
Either way — nice catch on the optimization. The fast-path-for-provably-safe-subdomain pattern is exactly right. |
|
Thanks @trevorprater — your Nice optimization — the 22–37% gain on short integers is confirmed and shipping. Closing as merged. |
…ETish - bytes.go: parseInt fast path for <=18-digit numbers (from PR #285 by @trevorprater, 22-37% faster on short integers) - bytes_test.go: -9223372036854775807 MC/DC witness for the slow-path neg branch that the fast path made unreachable for short numbers - SYS-REQ-061/062: aligned FRETish variable with the U+FFFD substitution behavior (was 'returns_error_for_missing_low_surrogate', now 'substitutes_replacement_for_missing_low_surrogate' — matches the actual DEFECT-260727-SNGT fix and encoding/json behavior) - MC/DC witnesses updated to match the new variable names - KI-2 evidence freshness re-stamped after bytes.go edit
Merge parseInt fast-path (PR #285) + align SYS-REQ-061/062 surrogate FRETish
|
Thank you! |
This adds a fast path for
parseIntwhen the numeric portion is shorter than19 decimal digits. In that case the value cannot overflow
int64, so the looponly needs to validate digits and accumulate into the named
int64returnvalue. Longer inputs continue through the existing
uint64overflow-checkedpath.
Validation:
Benchmark command:
Result on my machine (
darwin/arm64, Apple M4, Go 1.25.1):I also checked the final implementation against the previous implementation
with a temporary differential test over fixed edge cases and deterministic
random byte slices, including boundaries and malformed inputs.
I found the candidate direction while experimenting with Sleepy -
https://sleepy.run/mcp, then manually simplified and validated it before
submitting.