Uh oh!
There was an error while loading. Please reload this page.
Display of integers without raw pointers and without overflowing_literals - #135265
Conversation
rustbot
commented
Jan 8, 2025
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Noratrieb (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
tgross35
commented
Jan 8, 2025
r? tgross35 since I'm doing some work in this area anyway You should |
pascaldekloe
commented
Jan 8, 2025
No problem if this one gets rejected in favour of anything else @tgross35. I was just pleased to see the compiler doing this well. |
tgross35
commented
Jan 8, 2025
Actually ignore this, I was thinking this was in
No conflict :) Replacing unsafe code is always nice if there are no drawbacks. |
tgross35
commented
Jan 8, 2025
It looks like there may be some small regressions here, the new code doesn't elide a couple calls to Soon it will be possible to |
pascaldekloe
commented
Jan 11, 2025
What a gem that Compiler Explorer is @tgross35. I think the assembly looks good now. B.t.w., I tried bit shifting entries from the lookup table into a 64-bit register and write per 8 digits at once. The compiler "optimizes" such intermediate register away, and it goes for 16-bit copies instead. Maybe those small writes are actually faster. I don't know. 😂 |
pascaldekloe
commented
Jan 12, 2025
I found a way without compiler hinting which is even faster than the unsafe code as is. It requires buffers of an even byte-size. Needs a little more work for all integer sizes. https://github.com/pascaldekloe/b10/blob/e7d9813c1f74dc9137216f1b271303fb056e90ad/src/lib.rs#L1723 |
tgross35
commented
Jan 12, 2025
I am by no means a perf expert but I still can't imagine chasing down optimizations without it :)
Are you planning to update the PR with something like this? At a surface level the patch seems pretty reasonable but I didn't look too deep yet, I'll hold off on reviewing if you have something faster coming. |
pascaldekloe
commented
Jan 13, 2025
Yes, will give it a try @tgross35. Same surprise here as you're having. 🙂 |
tgross35
commented
Jan 13, 2025
@rustbot author (just comment |
pascaldekloe
commented
Jan 13, 2025
The speed gain is because (1) the loop decision no longer depends on the digit calculation, (2) it produces fewer instructions, and (3) it no longer needs a check for special case zero, which has a "significant" leading zero. Unfortunately the results are less optimal for the two benchmark cases in the core library: either zero or maximum digits in a loop. Apparently the branch prediction benefit does not outweight the per-4-digit tweak in such scenario. So now we have the explicit assertions as hint assertions too. Can you have a look @tgross35? @rustbot review |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
c8893fa to
f0a5e85Compare…35,ChrisDenton Display of integers without raw pointers and without overflowing_literals The benchmarks as is measure formatting speed of literals. The first commit `black_box`-es input to simulate runtime speed instead. The second commit replaces `unsafe` pointer optimizations with plain array indices. The performance is equivalent on Apple M1. Needs peer review on Intel. Happy to do the 128-bit version too if such change is welcome. try-job: x86_64-mingw-1 try-job: x86_64-mingw-2 try-job: i686-mingw try-job: i686-msvc-1 try-job: i686-msvc-2 try-job: x86_64-msvc-1 try-job: x86_64-msvc-2
bors
commented
Feb 3, 2025
This comment has been minimized.
This comment has been minimized.
bors
commented
Feb 3, 2025
💔 Test failed - checks-actions |
Uh oh!
There was an error while loading. Please reload this page.
821bc70 to
e863cbdComparee863cbd to
ebeaf2eComparetgross35
commented
Feb 3, 2025
@bors r=tgross35,ChrisDenton |
bors
commented
Feb 3, 2025
bors
commented
Feb 4, 2025
bors
commented
Feb 4, 2025
☀️ Test successful - checks-actions |
rust-timer
commented
Feb 4, 2025
Finished benchmarking commit (019fc4d): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (secondary 2.7%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary 1.0%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResults (primary -0.2%, secondary -0.1%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 778.131s -> 778.858s (0.09%) |
The benchmarks as is measure formatting speed of literals. The first commit
black_box-es input to simulate runtime speed instead.The second commit replaces
unsafepointer optimizations with plain array indices. The performance is equivalent on Apple M1. Needs peer review on Intel.Happy to do the 128-bit version too if such change is welcome.