bevy/crates
Alice Cecile 5a9bc28502
Support non-Vec data structures in relations (#17447)
# Objective

The existing `RelationshipSourceCollection` uses `Vec` as the only
possible backing for our relationships. While a reasonable choice,
benchmarking use cases might reveal that a different data type is better
or faster.

For example:

- Not all relationships require a stable ordering between the
relationship sources (i.e. children). In cases where we a) have many
such relations and b) don't care about the ordering between them, a hash
set is likely a better datastructure than a `Vec`.
- The number of children-like entities may be small on average, and a
`smallvec` may be faster

## Solution

- Implement `RelationshipSourceCollection` for `EntityHashSet`, our
custom entity-optimized `HashSet`.
-~~Implement `DoubleEndedIterator` for `EntityHashSet` to make things
compile.~~
   -  This implementation was cursed and very surprising.
- Instead, by moving the iterator type on `RelationshipSourceCollection`
from an erased RPTIT to an explicit associated type we can add a trait
bound on the offending methods!
- Implement `RelationshipSourceCollection` for `SmallVec`

## Testing

I've added a pair of new tests to make sure this pattern compiles
successfully in practice!

## Migration Guide

`EntityHashSet` and `EntityHashMap` are no longer re-exported in
`bevy_ecs::entity` directly. If you were not using `bevy_ecs` / `bevy`'s
`prelude`, you can access them through their now-public modules,
`hash_set` and `hash_map` instead.

## Notes to reviewers

The `EntityHashSet::Iter` type needs to be public for this impl to be
allowed. I initially renamed it to something that wasn't ambiguous and
re-exported it, but as @Victoronz pointed out, that was somewhat
unidiomatic.

In
1a8564898f,
I instead made the `entity_hash_set` public (and its `entity_hash_set`)
sister public, and removed the re-export. I prefer this design (give me
module docs please), but it leads to a lot of churn in this PR.

Let me know which you'd prefer, and if you'd like me to split that
change out into its own micro PR.
2025-01-20 21:26:08 +00:00
..
bevy_a11y Move #![warn(clippy::allow_attributes, clippy::allow_attributes_without_reason)] to the workspace Cargo.toml (#17374) 2025-01-15 01:14:58 +00:00
bevy_animation Relationships (non-fragmenting, one-to-many) (#17398) 2025-01-18 22:20:30 +00:00
bevy_app Create bevy_platform_support Crate (#17250) 2025-01-20 20:45:30 +00:00
bevy_asset Switch bevy_asset to core::prelude (#17442) 2025-01-20 04:14:48 +00:00
bevy_audio Relationships (non-fragmenting, one-to-many) (#17398) 2025-01-18 22:20:30 +00:00
bevy_color Move #![warn(clippy::allow_attributes, clippy::allow_attributes_without_reason)] to the workspace Cargo.toml (#17374) 2025-01-15 01:14:58 +00:00
bevy_core_pipeline Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00
bevy_derive Bump Version after Release (#17176) 2025-01-06 00:04:44 +00:00
bevy_dev_tools Rename TargetCamera to UiTargetCamera (#17403) 2025-01-19 19:56:57 +00:00
bevy_diagnostic Create bevy_platform_support Crate (#17250) 2025-01-20 20:45:30 +00:00
bevy_dylib Move #![warn(clippy::allow_attributes, clippy::allow_attributes_without_reason)] to the workspace Cargo.toml (#17374) 2025-01-15 01:14:58 +00:00
bevy_ecs Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00
bevy_encase_derive Bump Version after Release (#17176) 2025-01-06 00:04:44 +00:00
bevy_gilrs Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00
bevy_gizmos Reworked Segment types into their cartesian forms (#17404) 2025-01-19 03:54:45 +00:00
bevy_gltf Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00
bevy_image Move #![warn(clippy::allow_attributes, clippy::allow_attributes_without_reason)] to the workspace Cargo.toml (#17374) 2025-01-15 01:14:58 +00:00
bevy_input Create bevy_platform_support Crate (#17250) 2025-01-20 20:45:30 +00:00
bevy_input_focus Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00
bevy_internal Create bevy_platform_support Crate (#17250) 2025-01-20 20:45:30 +00:00
bevy_log Move #![warn(clippy::allow_attributes, clippy::allow_attributes_without_reason)] to the workspace Cargo.toml (#17374) 2025-01-15 01:14:58 +00:00
bevy_macro_utils Move #![warn(clippy::allow_attributes, clippy::allow_attributes_without_reason)] to the workspace Cargo.toml (#17374) 2025-01-15 01:14:58 +00:00
bevy_math Reworked Segment types into their cartesian forms (#17404) 2025-01-19 03:54:45 +00:00
bevy_mesh Move #![warn(clippy::allow_attributes, clippy::allow_attributes_without_reason)] to the workspace Cargo.toml (#17374) 2025-01-15 01:14:58 +00:00
bevy_mikktspace Move #![warn(clippy::allow_attributes, clippy::allow_attributes_without_reason)] to the workspace Cargo.toml (#17374) 2025-01-15 01:14:58 +00:00
bevy_pbr Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00
bevy_picking Create bevy_platform_support Crate (#17250) 2025-01-20 20:45:30 +00:00
bevy_platform_support Create bevy_platform_support Crate (#17250) 2025-01-20 20:45:30 +00:00
bevy_ptr Update safety docs for Ptr::assert_unique (#17394) 2025-01-16 03:25:19 +00:00
bevy_reflect Create bevy_platform_support Crate (#17250) 2025-01-20 20:45:30 +00:00
bevy_remote Relationships (non-fragmenting, one-to-many) (#17398) 2025-01-18 22:20:30 +00:00
bevy_render Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00
bevy_scene Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00
bevy_sprite Move #![warn(clippy::allow_attributes, clippy::allow_attributes_without_reason)] to the workspace Cargo.toml (#17374) 2025-01-15 01:14:58 +00:00
bevy_state Create bevy_platform_support Crate (#17250) 2025-01-20 20:45:30 +00:00
bevy_tasks Create bevy_platform_support Crate (#17250) 2025-01-20 20:45:30 +00:00
bevy_text Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00
bevy_time Create bevy_platform_support Crate (#17250) 2025-01-20 20:45:30 +00:00
bevy_transform Relationships (non-fragmenting, one-to-many) (#17398) 2025-01-18 22:20:30 +00:00
bevy_ui Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00
bevy_utils Create bevy_platform_support Crate (#17250) 2025-01-20 20:45:30 +00:00
bevy_window Move #![warn(clippy::allow_attributes, clippy::allow_attributes_without_reason)] to the workspace Cargo.toml (#17374) 2025-01-15 01:14:58 +00:00
bevy_winit Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00