Skip to content

Split ordered and unordered TypeId maps#25053

Open
0xEgao wants to merge 1 commit into
bevyengine:mainfrom
0xEgao:TypeId-hashmap
Open

Split ordered and unordered TypeId maps#25053
0xEgao wants to merge 1 commit into
bevyengine:mainfrom
0xEgao:TypeId-hashmap

Conversation

@0xEgao

@0xEgao 0xEgao commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Objective

Fixes #24642.

TypeIdMap became backed by IndexMap in #23864, making order-preserving removals O(n), including removal-heavy component registration paths.

Solution

  • Restored TypeIdMap as a hash-backed map with average O(1) removal.
  • Added TypeIdIndexMap for call sites that require insertion order.
  • Kept ordered storage for gizmo handles, custom attributes, and related-scene processing.
  • Replace unnecessary shift_remove calls with remove.

No new tests were added. Existing affected tests and compilation checks pass.

@beicause

Copy link
Copy Markdown
Member

Kept ordered storage for gizmo handles, custom attributes, and related-scene processing.

From the comment GizmoHandles needs to preserve order. But I don't know the reason for the other two places.

@0xEgao 0xEgao left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Kept ordered storage for gizmo handles, custom attributes, and related-scene processing.

From the comment GizmoHandles needs to preserve order. But I don't know the reason for the other two places.

  • CustomAttributes preserves insertion order because its existing iteration test explicitly relies on attributes being returned in builder insertion order.
  • ResolvedScene::related is iterated while related entities are spawned and relationship targets are populated. Keeping it ordered makes entity allocation and relationship processing deterministic.

@alice-i-cecile alice-i-cecile added C-Performance A change motivated by improving speed, memory usage or compile times A-ECS Entities, components, systems, and events S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 18, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in ECS Jul 18, 2026

@alice-i-cecile alice-i-cecile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like this change, but I worry about the migration path. Can we do TypeIdIndexMap and TypeIdHashMap for explicitness, keeping TypeIdMap as a deprecated type alias for the former with a deprecation note about choosing between them?

@alice-i-cecile alice-i-cecile added M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 18, 2026
@0xEgao

0xEgao commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

I like this change, but I worry about the migration path. Can we do TypeIdIndexMap and TypeIdHashMap for explicitness, keeping TypeIdMap as a deprecated type alias for the former with a deprecation note about choosing between them?

Hmm makes sense. Changing TypeIdMap in place silently changes its iteration semantics and Entry API.
I’ll add explicit TypeIdIndexMap and TypeIdHashMap aliases, and keep TypeIdMap as a deprecated alias for TypeIdIndexMap.

@0xEgao

0xEgao commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

I have made the changes, the changeset grew larger because all internal uses were migrated to explicit TypeIdHashMap or TypeIdIndexMap aliases. This avoids deprecated internal usage and demonstrates the intended migration path.

cc -: @alice-i-cecile

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times D-Straightforward Simple bug fixes and API improvements, docs, test and examples M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

Revisit TypeIdMap type and whether the places where it's used need to preserve insertion order

4 participants