perf: specialize decimal digit scanning - #1097
Open
pelletier wants to merge 1 commit into
Open
Conversation
scanDigitsWithUnderscores pays an indirect isInRange call per byte. Decimal runs — the overwhelmingly common case: every integer, float fraction, and exponent — now scan through a specialized loop with the range test inlined. Hex, octal, and binary literals keep the generic scanner. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Splitting #1088: this PR carries one optimization technique so its impact and review surface stay isolated.
What
scanDigitsWithUnderscorespays an indirectisInRangefunction call per byte. Decimal runs — every integer, float fraction, and exponent, the overwhelmingly common case — now scan throughscanDecimalDigits, a specialized loop with the range test inlined and the same underscore validation (and error message). Hex, octal, and binary literals keep the generic scanner.Impact
Benchmarked on a dedicated linux/amd64 spot VM (t2d), go1.26.4, interleaved A/B vs the base of this PR, benchstat over 10 samples per side:
UnmarshalDataset/canada: -13.09%UnmarshalDataset/code: -6.49%Unmarshal/SimpleDocument/map: -2.97%RealWorldContainerdConfig: +1.59%Marshal/HugoFrontMatter: +3.18%Full benchstat (sec/op, allocs/op)
sec/op
allocs/op
🤖 Generated with Claude Code