-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Optimize thread::panicking() #56469
Optimize thread::panicking() #56469
Conversation
IIRC |
@eddyb All right, I removed |
@Amanieu ran the benchmark from the original comment on an aarch64 machine and got:
|
@eddyb I wonder, should we perhaps mark functions accessing a |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Ah yeah |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
That looks like a reasonable strategy to me! This makes me think though that we may want to extend the I think that if we remove the branch the current I suspect that'd be nice to have for more use cases eventually than just this one panic count case, and we could probably use it in a few places in libstd! |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
I'm not sure if this PR is worth it anymore... :( It seems it reduces the time needed to lock a
Yeah, perhaps that might be a good thing to do! We could have something like the following syntax for constant-initialized thread-locals: thread_local! {
static ref FOO: Foo = const { Foo };
} Or do you think we'd do that somehow differently? |
|
@Amanieu All right, I'll benchmark again once that gets merged. Oh, and I also just realized we call Also, the poison flag is an |
Ah ok! @stjepang should we perhaps close this and wait for the parking lot PR instead then? |
Sure! Closing. |
Change a
thread_local!
to faster#[thread_local]
.This avoids the useless check of whether the
PANIC_COUNT
variable has been initialized on every call toPANIC_COUNT.with()
.I made additional changes:
PANIC_COUNT
by0
inthread::panicking()
, just read it.Add a few#[inline]
s just to make sure these small functions get inlined.Benchmark that proves replacing
thread_local!
with#[thread_local]
is worth it:Results (on my x86-64 machines):
cc @Amanieu - yay, faster mutex poisoning?
r? @alexcrichton