arc: improve codegen of drop - #162178
arc: improve codegen of drop#162178ruriww wants to merge 4 commits into
Conversation
pub fn drop_it_like_its_hot(_: Arc<()>) {}
sd a0, 0(sp)
amoadd.d.rl a0, a1, (a0)
li a1, 1
- bne a0, a1, .LBB6_2
- fence r, rw
+ beq a0, a1, .LBB6_2
+ ld ra, 8(sp)
+ addi sp, sp, 16
+ ret
+.LBB6_2:
mv a0, sp
call Arc::drop_slow
-.LBB6_2:
ld ra, 8(sp)
addi sp, sp, 16
ret |
|
Thanks for the pull request, and welcome! The Rust Project has assigned @Mark-Simulacrum (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks. Please see the contribution instructions and our LLM policy for more information. 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: improve codegen of drop
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (7aa9fe8): comparison URL. Overall result: ❌✅ regressions and improvements - BENCHMARK(S) FAILEDBenchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf ❗ ❗ ❗ ❗ ❗
❗ ❗ ❗ ❗ ❗ 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 -1.3%, secondary -3.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -2.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.2%, secondary -0.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: missing data |
Is this something I have to take care of? The instruction regression makes sense, it's demonstrated in the diff snippet I showed above. |
|
No, you can ignore that, we have some intermittent trouble with git, sorry. |
| // This function was moved locally since there is only one caller, | ||
| // and makes it easier to reason about the the outlined fence. |
There was a problem hiding this comment.
Drive-by review: this code comment looks like a commit message. I don't think it holds value by itself.
|
|
I'm pretty certain this is caused by the |
This comment has been minimized.
This comment has been minimized.
|
Removed the cold hint. I had AI help me dig deeper into the performance numbers only, here are the results: PGO data shows that the |
There was a problem hiding this comment.
Especially given the potential problems (see first comment), is there a concrete motivation for this change? The assembly diff in #162178 (comment) doesn't seem necessarily sufficient to motivate tweaking this code by itself.
| fn drop(&mut self) { | ||
| // Non-inlined part of `drop`. | ||
| #[inline(never)] | ||
| unsafe fn drop_slow<T: ?Sized, A: Allocator>(this: &mut Arc<T, A>) { |
There was a problem hiding this comment.
Why inline this into drop?
There was a problem hiding this comment.
I removed a comment that was originally in the code stating that it was easier to reason about the fence that was removed from fn drop but added to fn drop_slow.
|
@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: improve codegen of drop
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (00d30ba): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf 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.9%, secondary 0.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -1.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.4%, secondary -0.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 497.229s -> 494.834s (-0.48%) |
|
The same tt-muncher regression are odd, and I don't think that's to do with the changes here, x64 is implicitly AcqRel so the fence is a no-op. |
|
@bors try @rust-timer queue Let's get another perf run in to try to validate those numbers. It's possible that shuffling here has changed some inlining or other codegen decisions leading to slower compilation (even if the final assembly is the same). Do you have any evidence that moving this instruction makes a practical difference, at least in a microbench of some kind? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
arc: improve codegen of drop
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (12ea40b): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf 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 0.7%, secondary 1.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -2.4%, secondary 0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.4%, secondary -0.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 488.457s -> 488.75s (0.06%) |
|
It looks like the tt-muncher regression is real and is in Arc-related code... I think before we merge this investigating the details here to figure out where the extra instructions are coming from is warranted. Can you try to dig into that in more detail, e.g., compiling a few programs that drop Arcs in x86_64 code and see if you can find a case with extra instructions? This is the top of the diff from cachegrind: |
|
☔ The latest upstream changes (presumably #163472) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
View all comments
Move the fence into
drop_slow, which preserves the correct behavior and moving an actual instruction on arches like riscv to the outlined path.