Skip to content

Conversation

james7132
Copy link
Member

@james7132 james7132 commented Aug 29, 2025

Objective

The SparseArray in Edges uses a lot of memory for

Solution

  • Change Edges to use HashMap instead.
  • Key the HashMaps on a combination of the source archetype and the bundle.
  • Move Edges to the top level of World instead of individual Archetypes

This should result in the memory usage in Edges across a world scaling linearly with the number of observed Archetype moves instead of scaling quadratically with the number of archetypes.

TODO: Benchmark

Testing

CI

Future Work

If desirable, we may want to move the TypeId lookup into Edges, keying on (ArchetypeId, TypeId) instead. It'd return the associated BundleId and skip the Bundles typemap lookup.

@james7132 james7132 added A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Needs-Benchmarking This set of changes needs performance benchmarking to double-check that they help labels Aug 29, 2025
Copy link
Contributor

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Please review the instructions for writing migration guides, then expand or revise the content in the migration guides directory to reflect your changes.

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 M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Needs-Benchmarking This set of changes needs performance benchmarking to double-check that they help
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant