Arc: Remove unnecessary fmt::Display use for overflow assertion - #160731
Conversation
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Arc: Remove unnecessary fmt::Display use for overflow assertion
|
Note that I think we probably don't excercise this codepath very much in the compiler, so we probably won't see much impact in rustc-perf benchmarks. Are you trying to optimize something specific in the compiler or what's the reason you want to run perf on this? |
|
Thank you for your clarification, Currently one of my microbenchmarked PRs is getting rollback because of bors bench reporting regression after the merge, So I assumed every performance related change requires a bors report. |
This comment has been minimized.
This comment has been minimized.
|
No worries, it's totally fine to do a perf run when you're not sure about the potential perf impact here.
For perf changes that don't impact compiler performance, it's a bit less straightforward. There are some runtime benchmarks on Apart from that, we often have codegen tests for these, or people asses the performance impact locally and include the benchmarks in the repo (we don't run those on CI, though, that would be too noisy). The specific procedure depends on the change. This PR is fairly straightforward and it's a cleanup on its own so I don't think it'll need much more convincing. But It'd be nice to capture this in a codegen test since you've already looked at the assembly and posted it in the description. |
|
Finished benchmarking commit (babfadb): comparison URL. Overall result: ❌✅ regressions and improvements - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -2.4%, secondary -0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (secondary 0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 458.758s -> 459.208s (0.10%) |
|
I think you could do even better by outlining the panicking case into a separate, |
|
@panstromek Thank you for your complete and detailed explanation, I will look into the codegen tests. @joboet Thanks alot for the hint! It removes 3 more instructions! just a push rax and call to the function. increase_counter:
test rdi, rdi
js .LBB1_2
inc rdi
mov rax, rdi
ret
.LBB1_2:
push rax
call example[4823d063a3151a8b]::panic_arc_overflow |
This comment has been minimized.
This comment has been minimized.
|
Is there anyway to rerun the CI? It seem unrelated to my changes. |
commented
Aug 8, 2026
|
r? joboet |
commented
Aug 8, 2026
|
|
commented
Aug 10, 2026
Try force-pushing with a new commit hash: git commit --amend --no-edit && git push --force |
d3ea60f to
c1bfb4b
Compare
commented
Aug 11, 2026
|
Thanks! |
This PR removes unnecessary
fmt::Displaygenerated assembly because of use of formatting in the overflow check assertion(assert!(n <= MAX_REFCOUNT, "{}", INTERNAL_OVERFLOW_ERROR);).This reduces generated x64 assembly for counter increment(simplified) from:
To:
Godbolt link:
https://godbolt.org/z/3qjxooYWM
I expect bors to report a binary size reduction for all programs using Arc. There might also be performance improvements as a byproduct of CPU cache hit increase.