Repository navigation
Conversation
TryParseInt32D was the last large, fully unrolled Utf8Parser integer parser (659 bytes of IL). It falls just outside the JIT's profitability threshold for inlining, so Utf8Parser.TryParse(..., out int, ...) pays a call that the other integer overloads don't. Parsing as Int64 and range-checking accepts and rejects the same inputs and is small enough to inline. Fixes dotnet#136761 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-numerics |
Member
|
This seems worse than just doing the same parsing implementation pattern for It's also largely unnecessary as |
Instead of calling TryParseInt64D and range-checking the result, parse Int32 with the same loop as TryParseInt64D, using a 32-bit accumulator. It is still small enough to inline (231 bytes of IL, down from 659) and uses only 32-bit arithmetic. Co-Authored-By: Claude Opus 5.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.
Fixes #136761
TryParseInt32Dwas the last large, fully unrolledUtf8Parserinteger parser (659 bytes of IL). It sits just outside the JIT's profitability threshold for inlining, soUtf8Parser.TryParse(..., out int, ...)pays a call that the other seven integer overloads don't. This change implements it asTryParseInt64D+ a range check, which accepts and rejects the same inputs and is small enough to inline (+6/−133 lines).The
sbyte/short/byte/ushort/uintparsers are unchanged: they already inline, and routing them through the 64-bit parser is slower for them.Behavior
Unchanged, including:
+or-, and-0bytesConsumed = 0andvalue = 0on failureInputs that overflow
intbut fit inlongare now rejected after parsing instead of at the 11th digit.Tests
Added
D-formatInt32cases with 22+ leading zeros (MaxValue,MinValue,MaxValue + 1). Inputs of 19+ bytes now go throughTryParseInt64D's overflow-checked loop, and nothing covered that.System.Memory.Testswith-namespace System.Buffers.Text.Tests: 44,437 passed, 0 failed.Performance
BenchmarkDotNet 0.16.0-preview.2, i9-14900K with every process pinned to P-cores. Local Release builds of main (591622c) and this change in one run; only
System.Private.CoreLib.dlldiffers. The benchmark isUtf8Parser.TryParse(bytes, out int value, out int consumed) ? value + consumed : -1.042-712345123456789-2147483648Code this change doesn't touch moved by up to ±25% between the two builds in the same run (layout noise). So the 1–2 digit wins are clear, and the longer inputs are a wash. The issue has the analysis and the JIT-knob experiments.
🤖 Generated with Claude Code