-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add a short-circuiting path to slice comparison #113576
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
Conversation
r? @m-ou-se (rustbot has picked a reviewer for you, use r? to override) |
Given that this PR is made in hope of improving performance, I guess performance benchmarks would be appreciable, but I don't think I can start those myself. |
@bors try |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit 1616ffd67536e6201f8cda5fce4da6441fa750d6 with merge 8fcfeecab188ad3fc76fa0e22b6015e3007d8caa... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (8fcfeecab188ad3fc76fa0e22b6015e3007d8caa): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDBenchmarking 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 may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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 sizeResultsThis 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: 656.645s -> 656.898s (0.04%) |
It's counterintuitive as hell, but I can't say I'm that surprised. "You're comparing something with itself, that's gonna be |
Yeah this is indeed not so surprising as comparing the exact same slice is pretty rare. I've force-pushed a new version that generates branch-less assembly using conditional moves, which may be better, but I have little hope. |
This adds a short-circuiting path to slice comparison using the fact that two slices of the same length and pointing at the same address are equal.
I'll try to see if it let me do it myself, otherwise I'll need you to do it :) @bors try edit: It did not. |
@krtab: 🔑 Insufficient privileges: not in try users |
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit b0ca5ff with merge ef9db8293d0b16a1e6a3d43fbee50ecbeb0b4290... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (ef9db8293d0b16a1e6a3d43fbee50ecbeb0b4290): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDBenchmarking 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 may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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 sizeResultsThis 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: 657.774s -> 658.13s (0.05%) |
Well I guess that's all I could try. I'm not sure how representative of "the typical workload" these benchmarks are but they are not that surprising either so feel free to close this if you don't think this is mergeable as is @workingjubilee, and thanks for the review. |
rustc's workload is heavily dominated by "branchy" code and it does exercise a lot of Vecs, but it doesn't do as much work on slice comparison I think. On the other hand it doesn't not: this is not like a floating-point benchmark where the compiler is completely useless. So while we may want to reexamine this question when we get a better perf suite which has more actual programs to test, instead of just the compiler's own benchmarks, it's a pretty bad sign without further motivation. So yeah, closing. |
This adds a short-circuiting path to slice comparison using the fact that two slices of the same length and pointing at the same address are equal.
Ideally this would be implemented for both:
comparisons where A is B (cannot be done currently due to limitation in trait specialization)edit: this is false, see float for example