-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Optimize DateOnly properties and deconstruct #103352
Conversation
Tagging subscribers to this area: @dotnet/area-system-datetime |
ushort daySinceMarch1 = (ushort)((uint)u2 / DateTime.EafDivider); | ||
int n3 = 2141 * daySinceMarch1 + 197913; | ||
// Return 1-based day-of-month | ||
return (ushort)n3 / 2141 + 1; |
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.
here and in above - don't you just effectively inline DateTime.Day/Month/Year by hands? Shouldn't it be JIT's resposobility?
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.
In effect it circumvents 64-bit multiplication, 64-bit bitwise-and, 64-bit division; and replaces it with a 32-bit shift.
Should we assume JIT takes care of 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.
I agree with @EgorBo. I don't think we need to complicate the code just to do what the JIT can do. I am concerned about the code maintainability. Keeping it simple is easier to touch in the future.
I appreciate trying to optimize here but I have a concern the new code is more involving and will be more difficult to maintain. Is there any issue forcing to try optimizing such cases? I mean anyone complaint about the perf of the cases involved or this optimization affecting any hot path scenario. |
Fair enough. Working with financial applications; discrete dates (and numerics) is a big part of the values the calculations are done on, and where a significant CPU time is spent. Thanks! |
Algorithms are modified copies of the respective
DateTime
properties (andGetDate
method).It is possible to make the code shared between
DateTime
andDateOnly
. Could probably be done with an input "six hour count", but it feels a bit weird. Opinions?Benchmark results (source):