-
Notifications
You must be signed in to change notification settings - Fork 161
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
IndexMap / IndexSet comparison isn't order-aware. #153
Comments
This is a breaking change. Not sure if you really want to take this but I think it's the right thing to do. Fixes indexmap-rs#153
When entering or leaving fullscreen in youtube, we spend most of the restyle time diffing custom properties, under IndexMap::eq. Turns out that IndexMap equality is not order-aware, and thus you actually need to make a hashmap lookup for each entry in the map, which is unnecessarily inefficient. Instead, just compare the iterators. See indexmap-rs/indexmap#153. Differential Revision: https://phabricator.services.mozilla.com/D89434
It's been this way ever since I've added this as a possible change for 2.0 in #135. |
When entering or leaving fullscreen in youtube, we spend most of the restyle time diffing custom properties, under IndexMap::eq. Turns out that IndexMap equality is not order-aware, and thus you actually need to make a hashmap lookup for each entry in the map, which is unnecessarily inefficient. Instead, just compare the iterators. See indexmap-rs/indexmap#153. Differential Revision: https://phabricator.services.mozilla.com/D89434 UltraBlame original commit: d46a20917d66d3c7fc9ada2204eae0af92365e08
When entering or leaving fullscreen in youtube, we spend most of the restyle time diffing custom properties, under IndexMap::eq. Turns out that IndexMap equality is not order-aware, and thus you actually need to make a hashmap lookup for each entry in the map, which is unnecessarily inefficient. Instead, just compare the iterators. See indexmap-rs/indexmap#153. Differential Revision: https://phabricator.services.mozilla.com/D89434 UltraBlame original commit: d46a20917d66d3c7fc9ada2204eae0af92365e08
When entering or leaving fullscreen in youtube, we spend most of the restyle time diffing custom properties, under IndexMap::eq. Turns out that IndexMap equality is not order-aware, and thus you actually need to make a hashmap lookup for each entry in the map, which is unnecessarily inefficient. Instead, just compare the iterators. See indexmap-rs/indexmap#153. Differential Revision: https://phabricator.services.mozilla.com/D89434 UltraBlame original commit: d46a20917d66d3c7fc9ada2204eae0af92365e08
When entering or leaving fullscreen in youtube, we spend most of the restyle time diffing custom properties, under IndexMap::eq. Turns out that IndexMap equality is not order-aware, and thus you actually need to make a hashmap lookup for each entry in the map, which is unnecessarily inefficient. Instead, just compare the iterators. See indexmap-rs/indexmap#153. Differential Revision: https://phabricator.services.mozilla.com/D89434
IndexMap is definitely a bit inbetween, it partly wants to be a drop-in for HashMap (that's the starting design, drop-in with extra features). That's the reason for preserving the same equality semantics. I think that a fully order preserving hashmap would be a different crate than this one. (One that preserves order on remove, efficiently). |
When entering or leaving fullscreen in youtube, we spend most of the restyle time diffing custom properties, under IndexMap::eq. Turns out that IndexMap equality is not order-aware, and thus you actually need to make a hashmap lookup for each entry in the map, which is unnecessarily inefficient. Instead, just compare the iterators. See indexmap-rs/indexmap#153. Differential Revision: https://phabricator.services.mozilla.com/D89434
I would love to see an opt-in order-preserving comparison. Here's an idea that wouldn't require a 2.0: Add an additional type parameter Happy to put together a PR if people are excited. |
I fear a proliferation of type parameters -- I proposed an index type in #147, and I think it's likely we'll want an An ordering parameter seems less necessary to me, because that's a relatively superficial change which you could implement with a wrapper, just using FWIW, I also did add order-aware comparisons for the slice proposal in #177. |
Yeah, that makes sense. The proposed |
Hopefully only until indexmap-rs/indexmap#153 may become resolved.
Ran into this bug as well, and yes it is a bug, because when |
@OvermindDL1 that just means that it has some properties that are not part of the equality check. You could say the same about iteration order on a regular |
std's In short, wouldn't expect capacities to be the same or so forth, but would expect for each key and index to have the same value output in both indexmaps that are equal as the index is a key. |
It's a bit of gray zone whether it should take into account the key order in equality. I think it's fine as it is, since it's just a HashMap in the end. However, I think it would be nice if it provided a method to check for equality that takes into account the order of the keys. |
The
|
FYI: I've reintroduced |
Thanks for your work and examples on this issue @cuviper ! Really helpful a year later when asking myself the same questions 👍 |
This looks like a bug to me. I'd expect this test-case to pass:
The maps are most definitely not the same, and if you're using
IndexMap
is because you care about ordering.This came up because I was doing some Firefox profiling, and transitioning youtube from fullscreen to not-fullscreen or vice versa spends a lot of time under
find()
comparing custom properties (doing the lookup inIndexMap::eq
). Turns out we don't actually need to do any lookup, and not being ordering aware is a correctness issue.The text was updated successfully, but these errors were encountered: