Simplify TryParseFormatO fractional-seconds handling#129005
Merged
danmoseley merged 1 commit intoJun 5, 2026
Merged
Conversation
The "O" (ISO 8601 round-trip) format always has exactly 7 fractional-second digits, which matches DateTime's tick precision (TimeSpan.TicksPerSecond is 10_000_000). The integer formed by those seven digits is therefore exactly the sub-second tick count, so we can pass it straight to TryAddTicks instead of routing it through a double divide / multiply / Math.Round round-trip. Bit-exact equivalent. Side benefit: small (~6%) speedup on Perf_DateTime.ParseO on R2R'd CoreLib (i9-14900K), measured with a same-process A/B against an unchanged Perf_DateTime.ParseR control. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-datetime |
Member
Author
|
I was testing copilot and had it do something useful 😄 |
Copilot stopped reviewing on behalf of
danmoseley due to an error
June 4, 2026 19:37
This was referenced Jun 5, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Simplify
TryParseFormatOfractional-seconds handlingThe
"O"(ISO 8601 round-trip) format always has exactly 7 fractional-second digits, which matchesDateTime's tick precision (TimeSpan.TicksPerSecond == 10_000_000). The integer formed by those seven digits is therefore exactly the sub-second tick count, so we can pass it straight toTryAddTicksinstead of routing it through adoubledivide / multiply /Math.Roundround-trip.The change is bit-exact: every one of the 10M possible 7-digit values produces the same tick count as before (verified by brute-force).
Tests
Existing
System.Tests.DateTimeTests(1378 tests) andSystem.Tests.DateTimeOffsetTests(737 tests, 2 platform-skipped) pass against a CoreLib built with the change.Microbenchmark
Side benefit: a small (~6%) speedup on
Perf_DateTime.ParseOon R2R'd CoreLib.Benchmarks used (unchanged, from
dotnet/performance):Perf_DateTime.ParseO— targetPerf_DateTime.ParseR— unchanged controlRun with BenchmarkDotNet
Job.Default, same-process A/B (both--coreRuns passed in one invocation so process-startup, ASLR, and thermal effects don't bias the comparison), affinity-pinned to a single P-core:Environment: Windows 11, Intel Core i9-14900K (P-core 0 pinned), .NET 11.0 R2R'd
System.Private.CoreLib(Release), BenchmarkDotNet v0.16.0-nightly.ParseR(control) is identical between the two binaries, confirming the harness is stable;ParseOimproves ~6% (~0.73 ns/call).Note
This PR was prepared with the assistance of GitHub Copilot.