Skip to content

Mismatched types and inaccessible methods for HashMap and HashSet in 0.16-rc #18690

Closed
@alice-i-cecile

Description

@alice-i-cecile

Background

rust-lang/hashbrown#563 changed the default hasher for hashbrown to one that doesn't meet our needs. #15801 updated us to that version of hashbrown, following our dependencies. We were originally using hashbrown::HashMap over std::HashMap due to the use of a faster, more vulnerable hashing algorithm, as Bevy apps are generally not exposed to malicious input in this way.

#17460 shuffled our types around, moving HashMap and HashSet into bevy_platform_support, as they replace functionality provided by Rust's std`.

As part of #15801, we also changed hashers.

#18350 attempts to explain this problem somewhat in the docs.

Problems

As discussed in bevyengine/bevy-website#2065, the migration for this is terrible: it's more explicit in confusing ways, there are prominent methods like new and with_capacity that are simply unusable, despite showing up in the docs!

Potential solutions

Use hashbrown's default hasher

This might or might not be slower than whatever we're using. It fixes the migration / UX issues, and avoids duplicate dependencies though!

The really critical stuff is already generally using EntityHashMap etc, which is very optimized. See #17078 for an example.

Downgrade to hashbrown 0.14

This gets us parity with Bevy 0.15, but duplicates the dependency in our tree.

It also doesn't allow us to use the deterministic FixedHash (or whatever else we may choose) by default.

Petition for a better API upstream that can handle non-standard hashers with generics

This would be great, but due to the need to specify generic type defaults when calling methods, it may not be readily accepted.

This is made much worse by the fact that hashbrown is used in and aligns with the std API for these types, which has very strict stability guarantees.

Fork hashbrown and change the default hasher

This also duplicates the code, but allows us to properly fix the issue and pull in new fixes and improvements from upstream.

This is strictly better than relying on 0.14 forever, but adds maintenance burden for a complex utilities crate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-UtilsUtility functions and typesC-DependenciesA change to the crates that Bevy depends onC-UsabilityA targeted quality-of-life change that makes Bevy easier to useP-RegressionFunctionality that used to work but no longer does. Add a test for this!X-ControversialThere is active debate or serious implications around merging this PR

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions