-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Make sure std::panic::Location::caller() gets optimized away. #93031
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
Make sure std::panic::Location::caller() gets optimized away. #93031
Conversation
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 543e77f with merge 6b9358f887a37cd96b09b534cb87993c48f0201e... |
☀️ Try build successful - checks-actions |
Queued 6b9358f887a37cd96b09b534cb87993c48f0201e with parent 7531d2f, future comparison URL. |
Finished benchmarking commit (6b9358f887a37cd96b09b534cb87993c48f0201e): comparison url. Summary: This benchmark run did not return any relevant changes. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking 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 led to changes in compiler perf. @bors rollup=never |
Overall it seems to be a slight (<0.3%) improvement. |
I was under the impression that some logging frameworks might generate many calls to In any case, this seems to be a small win overall. |
#96348 does the same thing. Closing this one. |
I noticed that using
#[track_caller]
andstd::panic::Location::caller()
result in function calls being generated even though all the information is available at compile time andstd::panic::Location::caller()
is basically a no-op.Marking
std::panic::Location::caller()
with#[inline]
allows the compiler to optimize these calls out.Without
#[inline]
a call tostd::panic::Location::caller()
will result in LLVM IR like:Notice that the constant
@alloc2
is passed into a call toLocation::caller()
just to be returned from it unmodified.With the
#[inline]
annotation that call just goes away: