-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Do not move thread-locals before dropping #141685
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: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
can you add a test? |
@Noratrieb Done. |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Do not move thread-locals before dropping Fixes #140816. I also (potentially) improved the speed of `get_or_init` a bit by having an explicit hot/cold path. We still move the value before dropping in the event of a recursive initialization (leading to double-initialization with one value being silently dropped). This is the old behavior, but changing this to panic instead would involve changing tests and also the other OS-specific `thread_local/os.rs` implementation, which is more than I'd like in this PR.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (71827ba): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary 4.3%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary -1.4%, secondary -14.6%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResults (primary -0.2%, secondary -0.1%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 777.949s -> 778.459s (0.07%) |
I don't have the necessary context here; reassigning. Though I will note the performance looks great! r? libs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the performance improvements speak for themselves...
When I wrote this code, I was hoping that storing the value in an enum
would allow for niche-optimisations. It'd be interesting to see whether doing that helps in the case of variables without destructors – but that shouldn't block this PR.
r=me with the nits addressed.
// access to self.value and may replace it. | ||
let mut old_value = unsafe { self.value.get().replace(MaybeUninit::new(v)) }; | ||
match self.state.replace(State::Alive) { | ||
State::Uninitialized => D::register_dtor(self), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you reintroduce the comments from the old version? I was confused for a second about why the destructor is only registered in this arm, the comment helped to avoid that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -0,0 +1,38 @@ | |||
//@ run-pass | |||
#![allow(stable_features)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing, it was left over after copying tls-init-on-init.rs
as a template.
I believe the most important part of that isn't the change in layout, it's separating |
Thank you! |
Fixes #140816. I also (potentially) improved the speed of
get_or_init
a bit by having an explicit hot/cold path.We still move the value before dropping in the event of a recursive initialization (leading to double-initialization with one value being silently dropped). This is the old behavior, but changing this to panic instead would involve changing tests and also the other OS-specific
thread_local/os.rs
implementation, which is more than I'd like in this PR.