-
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
[vm/runtime] Call tzset()
before localtime_r()
.
#61302
Conversation
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 |
If I'm correct, this fix was already applied on Android and MacOS but reverted for all three platforms for performance issue reasons on Android: I could create that patch no issue, but I don't have a clue how I would be able to performance test it for Android. I do have a Mac mini m1 here, so if it's required, I could do the same test as I did for Linux. |
@JesseRiemens thanks for the link. It seems to have been reverted because there were some TSAN failures. Though there is no information on what exactly was failing and I don't see any warnings around multithreading in Anyway, ignore my comment about Android because apparently they have fixed in Android O - |
Could you maybe add the following to
|
84839cb
to
28d7d1c
Compare
Done! I've added the comment in Just tested on my M1 mini, it doesn't seem to have this issue.
void OS::Init() {
// Calling tzset() is only necessary in Android API version 25 or earlier.
if (android_get_device_api_level() < 26) {
// In API version 25, calling tzset() results in a ~0.5% increase in
// Flutter startup latency. In API version 31, calling tzset() results in
// a >25% increase in startup latency.
tzset();
}
} So we accept the tradeoff that for older Android versions, we only initialize the timezone on startup and don't update it runtime so we don't have a slower |
https://dart-review.googlesource.com/c/sdk/+/444983 has been updated with the latest commits from this pull request. |
1 similar comment
https://dart-review.googlesource.com/c/sdk/+/444983 has been updated with the latest commits from this pull request. |
28d7d1c
to
2f8b9bb
Compare
https://dart-review.googlesource.com/c/sdk/+/444983 has been updated with the latest commits from this pull request. |
1 similar comment
https://dart-review.googlesource.com/c/sdk/+/444983 has been updated with the latest commits from this pull request. |
Could you apply the following patch on top of your change:
This should fix TSAN breakage (which is a false positive). |
2f8b9bb
to
73c0eb9
Compare
Done! |
https://dart-review.googlesource.com/c/sdk/+/444983 has been updated with the latest commits from this pull request. |
1 similar comment
https://dart-review.googlesource.com/c/sdk/+/444983 has been updated with the latest commits from this pull request. |
It seems this doesn't satisfy LUCI, anything else we could try? |
I am working on TSAN stuff here: https://dart-review.googlesource.com/c/sdk/+/445941, turns out all this code was just dead. I will ping here once I figure out the best shape of it. Sorry for the trouble :) |
I have sent https://dart-review.googlesource.com/c/sdk/+/445941 for review. Once that lands I will ping you here and you should be able to rebase your change (dropping changes to build/sanitizers/tsan_suppressions.cc which I have included into my CL). After that we should be able to land the change. I also noticed that presubmit checking is not happy because the code is not formatted. You should run |
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()`. This change doesn't apply to Android, as from Android O and later Bionic libc handles timezone changes automatically.
73c0eb9
to
de9cdcb
Compare
https://dart-review.googlesource.com/c/sdk/+/444983 has been updated with the latest commits from this pull request. |
1 similar comment
https://dart-review.googlesource.com/c/sdk/+/444983 has been updated with the latest commits from this pull request. |
Thank you for the contribution. The patch has landed! |
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.