-
-
Notifications
You must be signed in to change notification settings - Fork 3.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
Update hashbrown to 0.15 #15801
Update hashbrown to 0.15 #15801
Conversation
1f86e6e
to
89ccf19
Compare
89ccf19
to
7fb8bb7
Compare
@clarfonthey looks like there's a formatting issue somewhere, could you try running the formatter and push again? |
Yeah, I was running into some difficulties fixing the lints but will try and fix this today or tomorrow. |
Rereading the changelog, I misunderstood what hashbrown did and they actually switched to a better hash that we should probably use instead. Gonna probably find a way to factor that in. |
9e73303
to
bba0dda
Compare
crates/bevy_ecs/src/bundle.rs
Outdated
@@ -1422,8 +1422,11 @@ impl Bundles { | |||
.or_insert_with(|| { | |||
let (id, storages) = | |||
initialize_dynamic_bundle(bundle_infos, components, Vec::from(component_ids)); | |||
self.dynamic_bundle_storages | |||
.insert_unique_unchecked(id, storages); | |||
// SAFETY: We know the ID is unique |
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.
I'm adding this comment to appease the lint, but I actually don't know if we do know if the ID is unique.
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.
I´ve checked the places where Bundles::init_dynamic_info
was being used and most of them are internal facing, but I found EntityWorldMut::insert_by_ids
, EntityWorldMut::retain
and EntityWorldMut::clear
which might be public facing I think?
HashMap::insert_unique_unchecked
says:
/// This operation is safe if a key does not exist in the map.
///
/// However, if a key exists in the map already, the behavior is unspecified:
/// this operation may panic, loop forever, or any following operation with the map
/// may panic, loop forever or return arbitrary result.
So I'm unsure if we should say something like the caller ensures the uniqueness, and even add some notes in the EntityWorldMut
methods if applicable? I guess I'm thinking out loud. 😅
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.
So, I'm honestly fine just changing this to insert
and leaving it at that :p
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.
Okay, so, I double-checked and the bundle ID is always increasing here, and without concurrency, we don't need to worry about data races. So, I updated the comment to clarify it is actually unique and leaving it.
965855a
to
ed0e28a
Compare
This should be ready for review, modulo whatever tiny nitpicks CI throws at me. Not sure if the migration guide is adequate: not sure how much we care about bevy_utils' public API, as far as like, whether people should be using it or not. |
ed0e28a
to
0f2237a
Compare
What is better about foldhash vs ahash? Is it really worth taking the extra dependency? |
Final changes made:
|
(If someone could mark this as ready for final review, I'd appreciate it. I think this should qualify as ready.) |
21c8e65
to
ca0e5f2
Compare
(I'll try and take a look at the failures soon) |
Ah, fun: the singular PR that got in the queue before this one didn't result in any merge conflicts, but it did add more uses of Those have to be removed now, since |
ca0e5f2
to
44a6b54
Compare
(Merge conflict should be resolved; ready to merge now.) |
44a6b54
to
71989d9
Compare
(kind of shocked that |
(Okay, this time I waited until CI passed. Should be ready to merge now. <3) |
Thanks for shepherding this across the finish line <3 |
So, I had no idea about these patches that were being run in CI, but they seem pretty brittle-- it would be much better (IMHO) to use |
71989d9
to
829d57e
Compare
I also have genuinely no idea why that patch failed on this PR. It appears to be referencing an earlier change where the patch should have broken, but it somehow did not trigger until now. And there were no recent changes to the CI job, either. It just makes absolutely no sense why this PR would be the one to trigger it, but at least, it did, and I fixed it. |
Updating dependencies; adopted version of bevyengine#15696. (Supercedes bevyengine#15696.) Long answer: hashbrown is no longer using ahash by default, meaning that we can't use the default-hasher methods with ahasher. So, we have to use the longer-winded versions instead. This takes the opportunity to also switch our default hasher as well, but without actually enabling the default-hasher feature for hashbrown, meaning that we'll be able to change our hasher more easily at the cost of all of these method calls being obnoxious forever. One large change from 0.15 is that `insert_unique_unchecked` is now `unsafe`, and for cases where unsafe code was denied at the crate level, I replaced it with `insert`. ## Migration Guide `bevy_utils` has updated its version of `hashbrown` to 0.15 and now defaults to `foldhash` instead of `ahash`. This means that if you've hard-coded your hasher to `bevy_utils::AHasher` or separately used the `ahash` crate in your code, you may need to switch to `foldhash` to ensure that everything works like it does in Bevy.
Updating dependencies; adopted version of bevyengine#15696. (Supercedes bevyengine#15696.) Long answer: hashbrown is no longer using ahash by default, meaning that we can't use the default-hasher methods with ahasher. So, we have to use the longer-winded versions instead. This takes the opportunity to also switch our default hasher as well, but without actually enabling the default-hasher feature for hashbrown, meaning that we'll be able to change our hasher more easily at the cost of all of these method calls being obnoxious forever. One large change from 0.15 is that `insert_unique_unchecked` is now `unsafe`, and for cases where unsafe code was denied at the crate level, I replaced it with `insert`. ## Migration Guide `bevy_utils` has updated its version of `hashbrown` to 0.15 and now defaults to `foldhash` instead of `ahash`. This means that if you've hard-coded your hasher to `bevy_utils::AHasher` or separately used the `ahash` crate in your code, you may need to switch to `foldhash` to ensure that everything works like it does in Bevy.
Updating dependencies; adopted version of #15696. (Supercedes #15696.)
Long answer: hashbrown is no longer using ahash by default, meaning that we can't use the default-hasher methods with ahasher. So, we have to use the longer-winded versions instead. This takes the opportunity to also switch our default hasher as well, but without actually enabling the default-hasher feature for hashbrown, meaning that we'll be able to change our hasher more easily at the cost of all of these method calls being obnoxious forever.
One large change from 0.15 is that
insert_unique_unchecked
is nowunsafe
, and for cases where unsafe code was denied at the crate level, I replaced it withinsert
.Migration Guide
bevy_utils
has updated its version ofhashbrown
to 0.15 and now defaults tofoldhash
instead ofahash
. This means that if you've hard-coded your hasher tobevy_utils::AHasher
or separately used theahash
crate in your code, you may need to switch tofoldhash
to ensure that everything works like it does in Bevy.