-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Remove pointer comparison check before doing memcmp #71735
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
The issue also mentions that this change needs to be benchmarked. From past PRs, it looks like I need to request |
Only compiler team members can do that for you. |
@bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit bcd3c1f with merge e992a97da01ade25fd0eab2f30d9c5fe0e3e1591... |
Lol, this equality test has caused me much pain in Miri (not anymore, but it used to be a big problem)... and I never dared to question its existence. ;) |
☀️ Try build successful - checks-azure |
Queued e992a97da01ade25fd0eab2f30d9c5fe0e3e1591 with parent bd0bacc, future comparison URL. |
Presuming perf results are neutral (as I expect), I'm going to just go ahead with this; r? @Mark-Simulacrum I believe that we don't need library (or compiler team) sign off for a change like this -- if our internal performance tests don't indicate a significant win, I'm going to suggest that it's likely not important enough to have for the vast majority of Rust programs, and it is known that it hurts some optimizations on the LLVM side. I have confirmed that the case in #71602 is fixed by this PR locally -- both the functions in the issue description produce identical (and essentially optimal) codegen. |
Finished benchmarking try commit e992a97da01ade25fd0eab2f30d9c5fe0e3e1591, comparison URL. |
Debug builds seem to be regressed but that maybe just noise. |
Looks we we should have a codegen test then? These things regress very easily. |
Would the biggest use case in favour of the current pointer equality check be map keys that are compared for equality? Long Vec/String/Box slice or whatever it is that bottoms out in this comparison. More information about this change: #33892 (Use case: HTTP request parsing, it looks like)
|
@@ -5859,9 +5859,6 @@ where | |||
if self.len() != other.len() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(15 lines above) There's still a pointer comparison in the default fn equal
, probably remove in both places, if the comparisons should be removed
@seanmonstar Is pointer equality check still a likely win, and for which comparisons? |
@bluss I guess if you already have a copy of the map key (e.g. I agree that a codegen test would be nice, though I'm not sure how easy it would be. I hadn't seen the http benchmarks before, if those are reproducible today (can test using the try build above, via rustup-toolchain-install-master), that would be somewhat convincing to me. Though if it's really such a big improvement, I'd guess there's value in interning or other optimizations that would permit going further or at least always hitting the optimization? |
Added a codegen test for this. |
I'm going to mark as S-blocked as I would like for either @seanmonstar to respond with how relevant this is to hyper or for someone to try and run some benchmarks similar to what was noted in #33892 (comment) |
In Is there a simple-ish way I could test with and without the pointer check in current nightly? Before the original PR was merged, I could do the pointer check manually and run benchmarks... |
You should be able to do something like:
where bench can be run or whatever, of course. |
Though I guess that we still haven't updated this to remove the pointer comparison in the default (non-memcmp case) but I suspect for hyper it probably doesn't matter too much? We should probably test both. |
☔ The latest upstream changes (presumably #73643) made this pull request unmergeable. Please resolve the merge conflicts. |
After a discussion with the reviewer, closing this pr as there is no further progress or momentum on this. If you wish, you can make a new pr that addresses this issue if there's a better way possible of approaching this. Thanks for taking the time to contribute :) |
This resurrects rust-lang#71735. Fixes rust-lang#71602, helps with rust-lang#80140. r? `@Mark-Simulacrum`
Remove pointer comparison from slice equality This resurrects rust-lang#71735. Fixes rust-lang#71602, helps with rust-lang#80140. r? `@Mark-Simulacrum`
The hypothesis is that removing this pointer check will help improve performance since in most cases slices won't be compared with themselves.
Closes #71602