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

optimize DateTimeOffset.UtcNow by removing redundant verification #45281

Merged
merged 3 commits into from
Nov 30, 2020

Conversation

adamsitnik
Copy link
Member

@adamsitnik adamsitnik commented Nov 27, 2020

cuts 10% of the time on Windows and contributes to the Caching TE benchmark

[Benchmark]
public DateTimeOffset GetUtcNow() => DateTimeOffset.UtcNow;
BenchmarkDotNet=v0.12.1.1466-nightly, OS=Windows 10.0.18363.1198 (1909/November2019Update/19H2)
Intel Xeon CPU E5-1650 v4 3.60GHz, 1 CPU, 12 logical and 6 physical cores
.NET SDK=5.0.100-rc.2.20479.15
  [Host]     : .NET 5.0.0 (5.0.20.47505), X64 RyuJIT
  Job-MJJALX : .NET 6.0.0 (42.42.42.42424), X64 RyuJIT
  Job-NASKJQ : .NET 6.0.0 (42.42.42.42424), X64 RyuJIT
Method Toolchain Mean Ratio
GetUtcNow \after\CoreRun.exe 68.91 ns 0.90
GetUtcNow \before\CoreRun.exe 76.34 ns 1.00

the Caching benchmark shows +4.5% RPS improvement on Windows:

load before after
CPU Usage (%) 34 35
Cores usage (%) 957 978
Working Set (MB) 48 48
Build Time (ms) 7,922 4,230
Start Time (ms) 0 0
Published Size (KB) 76,401 76,401
First Request (ms) 85 83
Requests/sec 286,622 299,359
Requests 4,327,835 4,520,311
Mean latency (ms) 2.17 1.63
Max latency (ms) 218.08 250.79
Bad responses 0 0
Socket errors 0 0
Read throughput (MB/s) 901.12 942.08
Latency 50th (ms) 0.88 0.84
Latency 75th (ms) 0.93 0.88
Latency 90th (ms) 0.98 0.93
Latency 99th (ms) 52.50 32.75

@adamsitnik adamsitnik added the tenet-performance Performance related issue label Nov 27, 2020
@adamsitnik adamsitnik added this to the 6.0.0 milestone Nov 27, 2020
@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.

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

Thanks.

@benaadams
Copy link
Member

Need to change expected exception type in test System.Tests.DateTimeOffsetTests.Ctor_Long_TimeSpan_Invalid from ArgumentException to ArgumentOutOfRangeException

…ate to make sure thrown exceptions do not change
@adamsitnik
Copy link
Member Author

Need to change expected exception type in test

thanks! I could not find the failure logs due to #45357 I was not sure about changing the thrown exception (it would be a breaking change?) so I've changed the order of passed arguments.

@benaadams
Copy link
Member

it would be a breaking change?

It's a more derived exception so would be ok; though the test was doing an exact match which is why it broke

@adamsitnik adamsitnik merged commit 00417de into dotnet:master Nov 30, 2020
@adamsitnik adamsitnik deleted the DateTimeOffsetUtcNowPerf branch November 30, 2020 17:05
@ghost ghost locked as resolved and limited conversation to collaborators Dec 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants