-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Short-circuit Rc/Arc equality checking on equal pointers where T: Eq #42965
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @sfackler (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@rust-lang/libs Thoughts on this? It is an interesting semantic change. Conditioning the behavior on |
I'd personally be wary of having this implementation, I feel like using @joliss did you have some particular benchmarks and/or applications in mind that would benefit from this? It's also worth pointing out that we have a similar optimization for slices, but it's only done on types which can be considered bytewise equal, not for all types. |
I assumed that the |
What problems are you envisioning?
Here's our use case: We have a complex struct with several heap-allocated fields (strings and vectors of other structs), so comparing it expensive. We're using persistent data structure libraries like hamt-rs or im-rs, which use |
@alexcrichton I wouldn't say that the |
@joliss thanks for explaining the use case! I think that the question though sounds like it still should be punted to the standard library becuase hamt-rs and the like seem like they'd just face similar questions as to whether this is a valid optimization or not. I'm not worried about anything concrete per-se but you could imagine implementations of That line of reasoning can get sort of interesting because it's memory safe to have buggy implementations so we'd want to make sure nothing bad can happen here. I don't think this is a problem though because you can already have a buggy In any case, I'd personally still find the location of the implementation here a little odd. For example if we feel that we should apply such an optimization to As a final point, we currently avoid having |
Thanks for the PR, @joliss!
The difference was addressed in the original issue:
I agree with this line of reasoning; the tradeoffs around This strikes me as similar to a change we made elsewhere that essentially assumed the |
Hm I'm not sure that makes sense to me though? If |
The key sentence is this one:
The point is that, given an arbitrary For your average
The point is that, while there's not a huge semantic difference between |
I'm not sure I understand the underlying problem, but I'm happy to try and change my PR. However, I'm struggling with the development workflow on the Rust core repo, as I haven't been able to get incremental compilation to work. I tried |
Hello @joliss Are you using a You can find the example at https://github.com/rust-lang/rust/blob/master/src/bootstrap/config.toml.example You should configure it (it has extensive comments inside) and place it near Let's see if that will improve it a bit |
@joliss try |
@aturon sure yeah I don't disagree with any of that, but I'm worried about the gotchas here outside of "standard usage of Rc". For example here's a scenario that I would find very surprising. Similarly it seems claimed that the What I think I may be getting at is that in many case the standard library tries to be simple to be easily understandable but more importantly predictable. We've certainly departed from this pretty heavily with the usage of specialization as small optimizations here and there (especially with iterators and I'm wary of opening the floodgates for any and all specialization-related optimizations being added to the standard library, so I feel like we need to draw the line somewhere. I'm not sure what side of the line this specific optimization is on and I may just be playing devil's advocate too much. You're not going to find a concrete reason to not land this from me, so that means we should just r+ this and land it when it's ready. |
sooo do I hear an r+ from @aturon or @alexcrichton or @sfackler? :) |
@carols10cents We're currently waiting on some fixes from the author. (Some realistic benchmark numbers would be welcome but not required). Otherwise we are good to go. |
Hi @joliss! Just a friendly ping -- do you need any help on this? |
Closing due to inactivity to help clear out the queue, but please feel free to resubmit or ping us to reopen if comments are addressed! |
Quick update: I remember there were some things we might or might not want to change about this, but I gave up on updating this PR because recompilation is incredibly slow for me and the disk space requirements blow the size of my development VM. If anybody else wants to take over this patch, please have at it! (It might in fact be mergeable as is, but I'm not 100% sure.) |
Short-circuit Rc/Arc equality checking on equal pointers where T: Eq based on #42965 Is the use of the private trait ok this way? Is there anything else needed for this to get pulled?
add comment to `Rc`/`Arc`'s `Eq` specialization in addition to rust-lang#56550 rust-lang#42965 (comment)
Closes #42655
Some notes:
rc1 < rc2
could returnfalse
if they point to them same object whereT: Eq
. It's perhaps a less clear-cut case than equality checking, so I decided to leave it out. We can always add it later if somebody can make a good argument.touch src/liballoc/rc.rs && ./x.py test -i src/liballoc --test-args rc::
takes 15 minutes (it recompiles a whole bunch of things afterliballoc
.) Am I doing something wrong?