Skip to content
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

Delete DateTime FCalls and switch to fully managed implementation #46690

Merged
merged 1 commit into from
Jan 8, 2021

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented Jan 7, 2021

No description provided.

@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@jkotas
Copy link
Member Author

jkotas commented Jan 7, 2021

Now that we have SuppressGCTransition modifiers for function pointers thanks for @jkoritzinsky, we can get rid of the DateTime FCalls that existed for performance reasons and unify the code accross runtimes.

On Windows without leap time second support, this change makes DateTime.UtcNow about 5% faster. On Windows with lead time second support, the performance impact of this change is in the noise range.

This change includes the straightforward parts from #44771. One of my motivation for doing this sooner rather than later is to start getting real-world millage on SuppressGCTransition to shake out corner-case bugs in it if there are any.

if (s_systemSupportsLeapSeconds)
{
FullSystemTime time;
GetSystemTimeWithLeapSecondsHandling(&time);

if (Interop.Kernel32.FileTimeToSystemTime(&fileTime, &time.systemTime) != Interop.BOOL.FALSE)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the methods were split into multiple parts to make the FCalls work. I have undone the split since it is no longer needed.

@@ -111,12 +155,14 @@ internal FullSystemTime(long ticks)
}
}

#if !CORECLR
internal static readonly bool s_systemSupportsPreciseSystemTime = SystemSupportsPreciseSystemTime();
private static unsafe readonly delegate* unmanaged[SuppressGCTransition]<long*, void> s_pfnGetSystemTimeAsFileTime = GetGetSystemTimeAsFileTimeFnPtr();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admit when support was added for function pointers I was not expecting us to be able to make such extensive use of it. Cool.

if (time->systemTime.Second > 59)
// Retry this check several times to reduce chance of false negatives due to thread being rescheduled
// at wrong time.
for (int i = 0; i < 10; i++)
Copy link
Member

@stephentoub stephentoub Jan 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This retry loop wasn't present previously, was it? You're just adding it proactively as you expect it could be an issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I am adding it proactively to make this check more robust. I think we are incorrectly falling back to imprecise UtcNow like one in million runtime startups without this loop. The loop will exit in first iteration on well-behaving systems.

Copy link
Member

@tarekgh tarekgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looks great to me. Thanks @jkotas for cleaning it all up.

should we close #45479 now?

@jkotas
Copy link
Member Author

jkotas commented Jan 7, 2021

should we close #45479 now?

#45479 has number of micro-optimizations that may be still valuable. I think we should keep it after resolving the conflict with this change.

@tarekgh
Copy link
Member

tarekgh commented Jan 7, 2021

#45479 has number of micro-optimizations that may be still valuable. I think we should keep it after resolving the conflict with this change.

I am seeing the PR has very minor such micro optimization (converting some long to ulong). would it make sense just to added these here instead? it is not much and also I will expect the perf gain from these would be small to justify the change. no pushing here though.

@srxqds
Copy link
Contributor

srxqds commented Jan 7, 2021

what effect on monovm?

@jkotas
Copy link
Member Author

jkotas commented Jan 8, 2021

converting some long to ulong

I have actually started doing that originally, but then the delta kept growing and the PR got harder to review. I prefer to take it smaller step at a time.

what effect on monovm?

MonoVM has been on the managed implementation already. This change is basically switching CoreCLR to the implementation that MonoVM has been using.

#46690 (comment) should improve the performance for MonoVM a bit. The improvement is likely in the noise range.

@jkotas jkotas merged commit 2c7ae5c into dotnet:master Jan 8, 2021
@jkotas jkotas mentioned this pull request Jan 8, 2021
@jkotas jkotas deleted the datetime branch January 27, 2021 02:16
@tarekgh
Copy link
Member

tarekgh commented Feb 2, 2021

#45318

@ghost ghost locked as resolved and limited conversation to collaborators Mar 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants