This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Improve throughput of UInt32/UInt64.{Try}Parse #18930
Merged
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.
As was recently done for Int32/Int64 in #18897, tjis ports the Utf8Parser approach to parsing to UInt32/UIn64.{Try}Parse, specifically for NumberStyles.Integer (the default).
Also fixes an issue discovered in the previous Int32/Int64 changes, where if the input both has an overflow and has a formatting error (e.g. Int32.Parse("12345678910blah"), we would end up throwing whichever error was hit first, which is a change from .NET Core 2.1 and netfx. The FormatException needs to be preferred over the OverflowException, which just means we can't bail early when overflow is detected. I'm putting up another corefx tests PR with more tests that cover this.
(I tried to stay fairly true to the Utf8Parser code, since time and effort was spent tuning those. However, this has yielded a fair amount of duplication now, with code repeated four times for each of Int32, UInt32, Int64, and UInt64. After all of the perf improvements are in, we should look to see whether we can retain almost all of the gains while reducing some of that duplication.)
Contributes to https://github.com/dotnet/corefx/issues/30612
cc: @jkotas, @ahsonkhan, @danmosemsft
Benchmark:
Before/After:
(Note that these numbers are from a different machine than the numbers in the Int32/Int64 PR, so they're not directly comparable to each other.)