bevy/crates
Carter Anderson b3a1db60f2 Proper prehashing (#3963)
For some keys, it is too expensive to hash them on every lookup. Historically in Bevy, we have regrettably done the "wrong" thing in these cases (pre-computing hashes, then re-hashing them) because Rust's built in hashed collections don't give us the tools we need to do otherwise. Doing this is "wrong" because two different values can result in the same hash. Hashed collections generally get around this by falling back to equality checks on hash collisions. You can't do that if the key _is_ the hash. Additionally, re-hashing a hash increase the odds of collision!
 
#3959 needs pre-hashing to be viable, so I decided to finally properly solve the problem. The solution involves two different changes:

1. A new generalized "pre-hashing" solution in bevy_utils: `Hashed<T>` types, which store a value alongside a pre-computed hash. And `PreHashMap<K, V>` (which uses `Hashed<T>` internally) . `PreHashMap` is just an alias for a normal HashMap that uses `Hashed<T>` as the key and a new `PassHash` implementation as the Hasher. 
2. Replacing the `std::collections` re-exports in `bevy_utils` with equivalent `hashbrown` impls. Avoiding re-hashes requires the `raw_entry_mut` api, which isn't stabilized yet (and may never be ... `entry_ref` has favor now, but also isn't available yet). If std's HashMap ever provides the tools we need, we can move back to that. The latest version of `hashbrown` adds support for the `entity_ref` api, so we can move to that in preparation for an std migration, if thats the direction they seem to be going in. Note that adding hashbrown doesn't increase our dependency count because it was already in our tree.

In addition to providing these core tools, I also ported the "table identity hashing" in `bevy_ecs` to `raw_entry_mut`, which was a particularly egregious case.

The biggest outstanding case is `AssetPathId`, which stores a pre-hash. We need AssetPathId to be cheaply clone-able (and ideally Copy), but `Hashed<AssetPath>` requires ownership of the AssetPath, which makes cloning ids way more expensive. We could consider doing `Hashed<Arc<AssetPath>>`, but cloning an arc is still a non-trivial expensive that needs to be considered. I would like to handle this in a separate PR. And given that we will be re-evaluating the Bevy Assets implementation in the very near future, I'd prefer to hold off until after that conversation is concluded.
2022-02-18 03:26:01 +00:00
..
bevy_app small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_asset Proper prehashing (#3963) 2022-02-18 03:26:01 +00:00
bevy_audio Update rodio 0.15 (#3846) 2022-02-03 04:25:44 +00:00
bevy_core small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_core_pipeline small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_crevice Don't panic in macro shape validation (#3647) 2022-01-15 22:14:43 +00:00
bevy_derive small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_diagnostic small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_dylib Release 0.6.0 (#3587) 2022-01-08 10:18:22 +00:00
bevy_dynamic_plugin Release 0.6.0 (#3587) 2022-01-08 10:18:22 +00:00
bevy_ecs Proper prehashing (#3963) 2022-02-18 03:26:01 +00:00
bevy_ecs_compile_fail_tests Release 0.6.0 (#3587) 2022-01-08 10:18:22 +00:00
bevy_gilrs Release 0.6.0 (#3587) 2022-01-08 10:18:22 +00:00
bevy_gltf small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_input Proper prehashing (#3963) 2022-02-18 03:26:01 +00:00
bevy_internal bevy_render: Use RenderDevice to get limits/features and expose AdapterInfo (#3931) 2022-02-16 21:17:37 +00:00
bevy_log Implement init_resource for Commands and World (#3079) 2022-02-08 23:04:19 +00:00
bevy_macro_utils small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_math Release 0.6.0 (#3587) 2022-01-08 10:18:22 +00:00
bevy_pbr bevy_render: Use RenderDevice to get limits/features and expose AdapterInfo (#3931) 2022-02-16 21:17:37 +00:00
bevy_reflect Proper prehashing (#3963) 2022-02-18 03:26:01 +00:00
bevy_render Proper prehashing (#3963) 2022-02-18 03:26:01 +00:00
bevy_scene small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_sprite small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_tasks small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_text small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_transform small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_ui Add FocusPolicy to NodeBundle and ImageBundle (#3952) 2022-02-15 22:31:51 +00:00
bevy_utils Proper prehashing (#3963) 2022-02-18 03:26:01 +00:00
bevy_window small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_winit small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00