ptr_eq
-first PartialEq
implementation for Mrc
/Irc
?
#1782
EndilWayfare
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am working on a project that works with rather beefy data parsed from files. It's mostly heap allocated types --
Vec
s andStrings
-- soMrc
/Irc
is a natural fit to pass that state down into child components. Avoiding unnecessary clones is fantastic, but profiling reveals a lot of time spent equality checking. The state from files is mostly immutable, changing only when a different file is loaded, so I pass around the app state that changes more often in a separateIrc
. The unchanging data still goes through a full equality check very frequently, though.I assumed that
Mrc
/Irc
used the fact that they are pointers to optimize equality checks, using aptr_eq
to short circuit comparisons. Probably, I assumed this because yew.rs encourages this pattern in optimizations. This kind of "shallow equality" is leveraged heavily in React and the broader JS ecosystem for persistent(ish) structures. Neither smart pointer does this, however, andIrc
doesn't even have aptr_eq
method.I propose changing the
PartialEq
implementation (at least forIrc
, since it's the one that is compared most frequently inComponent::change
) in addition to adding aptr_eq
method. This would play most nicely withNeqAssign
.The existing
PartialEq
implementation is purely a function of underlying data as it is: two pointers will compare equal if their data compares equal, even if it lives at two different addresses, so this proposal shouldn't change the semantics of existing programs.If we agree this would be a good plan, I can draft a pull request.
Beta Was this translation helpful? Give feedback.
All reactions