Skip to content

Use EntityIndexSet in Children - #25811

Open
SkiFire13 wants to merge 32 commits into
bevyengine:mainfrom
SkiFire13:chidren-entityindexset
Open

SkiFire13 wants to merge 32 commits into
bevyengine:mainfrom
SkiFire13:chidren-entityindexset

Conversation

@SkiFire13

@SkiFire13 SkiFire13 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Objective

From the original PR:

Objective

Solution

  • Use an index set for fast lookups, while maintaining insertion order and index lookups used by existing features.

@alice-i-cecile alice-i-cecile added this to the 0.20 milestone Sep 16, 2026
@alice-i-cecile alice-i-cecile added S-Needs-Review Needs reviewer attention (from anyone!) to move forward C-Bug An unexpected or incorrect behavior A-Transform Translations, rotations and scales I-Unsound A bug that results in undefined compiler behavior X-Uncontroversial This work is generally agreed upon C-Performance A change motivated by improving speed, memory usage or compile times labels Sep 16, 2026

@Victoronz Victoronz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this will simply shift performance characteristics of the underlying type, not improve them across the board.
For our use cases the change in performance trade-offs might end up being mostly a plus, but without performance benchmarks it is somewhat of an unknown.

Comment thread crates/bevy_ecs/src/hierarchy.rs Outdated
Comment thread crates/bevy_ecs/src/hierarchy.rs
Comment thread crates/bevy_ecs/src/hierarchy.rs
Comment thread crates/bevy_ecs/src/relationship/relationship_source_collection.rs
Comment thread crates/bevy_ecs/src/relationship/relationship_source_collection.rs
Comment thread crates/bevy_ecs/src/relationship/relationship_source_collection.rs
@SkiFire13
SkiFire13 force-pushed the chidren-entityindexset branch from 5640947 to 0f8ab5f Compare September 17, 2026 12:15
@github-actions

Copy link
Copy Markdown
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-25811

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

@alice-i-cecile alice-i-cecile added D-Complex Quite challenging from either a design or technical perspective. Ask for help! X-Contentious There are nontrivial implications that should be thought through S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed X-Uncontroversial This work is generally agreed upon S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 17, 2026
@alice-i-cecile

Copy link
Copy Markdown
Member

@SkiFire13 @Victoronz can you resolve comment threads as you work through the issues? I want to review this but it's hard for me to follow right now :)

@SkiFire13

Copy link
Copy Markdown
Contributor Author

@alice-i-cecile I resolved most of them, I only left one open waiting for the reply from @Victoronz

@alice-i-cecile alice-i-cecile added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Sep 17, 2026
@alice-i-cecile alice-i-cecile added the S-Needs-Benchmarking This set of changes needs performance benchmarking to double-check that they help label Sep 18, 2026
@alice-i-cecile

Copy link
Copy Markdown
Member

I want to see benchmarks of this before it merges: this is a major change in hot loop, at least partially motivated by improving performance.

@SkiFire13

Copy link
Copy Markdown
Contributor Author

@alice-i-cecile there should be a tentive benchmark in the original PR.

Unfortunately I will be on vacation without my pc for the next couple of days so I won't be able to make benchmarks for this. However consider that:

  • this is generally doing more work (checking that entities aren't in Children when before we didn't), so it can be slower
  • on the other hand when we do these checks it can be a little faster in cases where we have a lot of entities
  • the alternative for soundness would be doing this kind of children deduplication in the transform propagation every single frame for every children that might have changed. I would assume this to also be slower than the current situation

@alice-i-cecile

Copy link
Copy Markdown
Member

Yep, no worries. I'll run some benchmarks on Sunday myself, and see what we can do to improve things in general :) I agree that this is important work that shouldn't be dropped.

@SkiFire13

Copy link
Copy Markdown
Contributor Author

Apparently this approach may be flawed due to indexmap::set::MutableValues being safe 🫠

Should we just write our own IndexSet<Entity>?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Transform Translations, rotations and scales C-Bug An unexpected or incorrect behavior C-Performance A change motivated by improving speed, memory usage or compile times D-Complex Quite challenging from either a design or technical perspective. Ask for help! I-Unsound A bug that results in undefined compiler behavior S-Needs-Benchmarking This set of changes needs performance benchmarking to double-check that they help S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Contentious There are nontrivial implications that should be thought through

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UB found in EntityWorldMut::replace_children in multi-threaded with pure safe code Extremely slow entity despawning

4 participants