Skip to content

Conversation

xtqqczze
Copy link
Contributor

@xtqqczze xtqqczze commented Jul 27, 2025

The JIT compiler can treat TimeSpan.FromMinutes(1) as a constant and optimize it at compile time. In contrast, TimeSpan.Parse involves runtime string parsing and cannot be constant-folded, which adds unnecessary overhead.

TimeSpan.Parse may also behave differently depending on culture settings.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jul 27, 2025
`TimeSpan.Parse` may behave differently depending on culture settings.
@Clockwork-Muse
Copy link
Contributor

TimeSpan.Parse may behave differently depending on culture settings.

This may be true, but the original version also only ran parameter validation/construction once.

@tannergooding
Copy link
Member

It would be beneficial to share some diffs and/or benchmarks from this.

This looks like a pure improvement, but having the numbers just helps add the extra +1 to give people peace of mind.

@xtqqczze
Copy link
Contributor Author

Diffs are an improvement, as expected.

@tannergooding
Copy link
Member

Yep. Mostly looks like removing the static constructors (which should happen in T1 anyways) and that we do get the direct constant as expected.

Copy link
Contributor

Tagging subscribers to this area: @roji, @SamMonoRT
See info in area-owners.md if you want to be subscribed.

@tannergooding
Copy link
Member

This LGTM, but since its in a less touched area I will defer to the area owners on whether it meets the bar for merge: @SamMonoRT, @roji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Transactions community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants