Skip to content

Simplify constant TimeSpan retrieval #118097

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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 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
Copy link
Contributor

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

`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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

3 participants