library: optimize truncate method - #157123
Conversation
|
rustbot has assigned @Mark-Simulacrum. 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.
library: optimize truncate method
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (0b2c3b8): comparison URL. Overall result: no relevant changes - 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 countThis perf run didn't have relevant results for this metric. Max RSS (memory usage)This perf run didn't have relevant results for this metric. CyclesResults (primary 2.3%, secondary 2.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.0%, secondary -0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 511.654s -> 511.381s (-0.05%) |
|
The same, slightly improved assembly is generated if you remove or equal from the original condition. I.e. turn |
You’re correct that changing |
|
Can you post the diff you're expecting to see for this? Looking at the playground link from the description (https://play.rust-lang.org/?version=nightly&mode=release&edition=2024&gist=2e44cfb473fe7ed00c00c3993baf9768) this appers to be the diff. But this doesn't seem like it's really changing the performance? The core loop is entirely unchanged; the function header loses an extra branch, but that's about it... I doubt that matters that much. I don't think we should bother with tweaks like this personally without benchmarks to substantiate them (and even then it seems unlikely that we'd see an effect outside a microbenchmark). --- /tmp/old
+++ /tmp/new
@@ -1,4 +1,4 @@
-playground::foo: # @playground::foo
+playground::mytr: # @playground::mytr
# %bb.0:
pushq %r15
pushq %r14
@@ -7,25 +7,23 @@
pushq %rax
movq 16(%rdi), %r14
cmpq %r14, %rsi
- ja .LBB0_4
+ jae .LBB1_3
# %bb.1:
movq %rsi, %rbx
movq 8(%rdi), %r15
movq %rsi, 16(%rdi)
- je .LBB0_4
-# %bb.2:
movq __rustc::__rust_dealloc@GOTPCREL(%rip), %r12
-.LBB0_3: # =>This Inner Loop Header: Depth=1
+.LBB1_2: # =>This Inner Loop Header: Depth=1
movq (%r15,%rbx,8), %rdi
movl $4, %esi
movl $4, %edx
callq *%r12
incq %rbx
cmpq %rbx, %r14
- jne .LBB0_3
+ jne .LBB1_2
-.LBB0_4:
+.LBB1_3:
addq $8, %rsp
popq %rbx
popq %r12 |
Closes #76089
Slightly better code when the elements have drop glue, see #74172 (comment).
Slightly worse code for
truncate(0), see #78884 (comment). However, this is mitigated by the newclippy::manual_clearlint which is warn-by-default.