-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[vm/runtime] Call tzset()
before localtime_r()
.
#61302
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
base: main
Are you sure you want to change the base?
[vm/runtime] Call tzset()
before localtime_r()
.
#61302
Conversation
POSIX doesn't guarantee that the timezone is set correctly before calling `localtime_r()`, so we need to call `tzset()` first to ensure that the timezone information is up-to-date. As the glibc manual states: > According to POSIX.1-2001, `localtime()` is required to behave as though `tzset(3)` was called, while `localtime_r()` does not > have this requirement. For portable code, `tzset(3)` should be called before `localtime_r()`.
Thank you for your contribution! This project uses Gerrit for code reviews. Your pull request has automatically been converted into a code review at: https://dart-review.googlesource.com/c/sdk/+/444983 Please wait for a developer to review your code review at the above link; you can speed up the review if you sign into Gerrit and manually add a reviewer that has recently worked on the relevant code. See CONTRIBUTING.md to learn how to upload changes to Gerrit directly. Additional commits pushed to this PR will update both the PR and the corresponding Gerrit CL. After the review is complete on the CL, your reviewer will merge the CL (automatically closing this PR). |
https://dart-review.googlesource.com/c/sdk/+/444983 has been updated with the latest commits from this pull request. |
Do you know what is the cost associated with calling |
https://dart-review.googlesource.com/c/sdk/+/444983 has been updated with the latest commits from this pull request. |
I made a quick benchmark that does ten runs of 10 million DateTime.now() calls, and the results are below: The modded version, with the
The non-modified version:
That's 0.03466881 with mod vs 0.03436355 without mod; If you have any improvement to my benchmark method, please let me know. Edit: It actually looks like after repeated testing that the modified build is faster often, and I can't understand why. |
I think this looks good to me. Could you apply the same patch to |
Relevant info in #60191 (And duplicate #61303)
POSIX doesn't guarantee that the timezone is set correctly before calling
localtime_r()
, so we need to calltzset()
first to ensure that the timezone information is up-to-date.As the glibc manual states:
Contribution guidelines:
dart format
.Note that this repository uses Gerrit for code reviews. Your pull request will be automatically converted into a Gerrit CL and a link to the CL written into this PR. The review will happen on Gerrit but you can also push additional commits to this PR to update the code review.