-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
bevy_reflect: Replace HashTable
with HashMap
#15149
bevy_reflect: Replace HashTable
with HashMap
#15149
Conversation
Note: this is preparatory work for removing hashbrown in favor of std::collections
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
HashTable
with HashMap
This changes the semantics. It will consider two elements with the same hash as being the same, resulting in one overwriting the other when inserted or its lookup succeeding even if the set only contains the other. Since you mention AFAIK the std |
Well that makes a LOT more sense. So we expect there to be hash collisions. Am I correct in assuming I also think there might be an opportunity to combine
I began using a
|
I totally agree with this. There are also some weird differences between
That could work, but looks really ugly and likely also less efficient than what it can be. It feels a waste to allocate all those The stdlib's Edit: a simplier alternative may be writing a wrapper over |
Thanks for the explanation! It cleared up many of my misunderstandings. I think it's getting a little off topic for the original purpose of this pr. Since Regarding the incorrectness of |
Objective
This is preparatory work for removing
hashbrown
in favor of eitherstd::collections
orrustc_hash
(yet undecided) as discussed in #11478std::collections::{HashSet, HashMap}
andrustc_hash::{FxHashSet, FxHashMap}
are pretty much drop in replacements forhashbrown::{HashSet, HashMap}
, so no issues there, butcrates\bevy_reflect\src\set.rs
useshashbrown::HashTable
which has no std/rustc_hash equivalent.Solution
This pr replaces
HashTable
inDynamicSet
with aHashMap
. This is implemented similar toDynamicMap
, which itself uses aHashMap
internally.Testing
Testing with
cargo test --package bevy_reflect
passes.I haven't done any performance tests.
This change might consist of a small performance downgrade, since the old implementation used the
u64
fromPartialReflect::reflect_hash
directly as a hash for the table (instead of using a hash of the u64). But sinceDynamicMap
doesn't make any considerations to optimize things, I think this regression is fine.