-
Notifications
You must be signed in to change notification settings - Fork 5k
Refactor some DateTime and TimeSpan formatting/parsing methods #101640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1c1f006
Refactor some DateTime and TimeSpan formatting/parsing methods
lilinus 001ee0a
Fix assertion in TimeSpanParse.Pow10
lilinus 7800524
Merge branch 'main' into dt-ts-format-parse-helpers
lilinus decf099
Don't use Unsafe in TimeSpanParse.Pow10
lilinus 267d5e8
Revert changes to TimeSpanParse.Pow10
lilinus 61863e3
Revert "Revert changes to TimeSpanParse.Pow10"
lilinus 95857be
Change method name to Pow10UpToMaxFractionDigits
lilinus 2fe27c1
Fix TimeSpanParse.TimeSpanToken.NormalizeAndValidateFraction
lilinus dd64b42
Address feedback in TimeSpanParse
lilinus 5e171ed
Merge branch 'main' into dt-ts-format-parse-helpers
lilinus 0c04b2f
Change from Math.Round to uint divison in TimeSpanParse.NormalizeAndV…
lilinus 3cf992c
Merge branch 'main' into dt-ts-format-parse-helpers
lilinus e455150
Comment for rounding division in TimeSpanParse.NormalizeAndValidateFr…
lilinus 4e074fd
Merge branch 'main' into dt-ts-format-parse-helpers
lilinus ef86e5a
Update src/libraries/System.Private.CoreLib/src/System/Globalization/…
lilinus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if this dividing by 2 and dividing by power will be more performant than just calling Math.Round?
@tannergooding any opinion on that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting...I suppose floating point math could be much slower than integer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest reverting the code back to use Math.Round. It is even more readable and clear the intention of what the code does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Results on arm64 with the span bounds check removed:
BenchmarkDotNet v0.13.12, macOS Sonoma 14.4.1 (23E224) [Darwin 23.4.0]
Apple M2, 1 CPU, 8 logical and 8 physical cores
.NET SDK 8.0.204
[Host] : .NET 8.0.4 (8.0.424.16909), Arm64 RyuJIT AdvSIMD
DefaultJob : .NET 8.0.4 (8.0.424.16909), Arm64 RyuJIT AdvSIMD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you provide a public API benchmark that shows any noticeable perf difference? IMO, It doesn't make sense to benchmark internals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EgorBo Not sure about real-world benchmarks, but with the suggested change code size (on X64) is 172 bytes vs is 271 bytes.
https://csharp.godbolt.org/z/YcMKW5fza
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lilinus is it possible you run your perf tests again mentioned in #101640 (comment) with @xtqqczze suggestion to get some idea about the perf of this change? Thanks!
I am talking about the change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like
uint
division is slightly faster. I assume you want me to push back to that change so I will do it.Benchmark source:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lilinus looks you already did :-) I am fine with that as tt provides us with a smaller code size and a slightly faster performance as well.
One last ask, please add a comment above that line telling what is does to be easier for anyone reading the code understand what the code is doing.
@xtqqczze thanks for the suggestion!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment added 👍