Skip to content

Chained EntityCommands create useless temporary archetypes #5074

@alice-i-cecile

Description

@alice-i-cecile

What problem does this solve or what need does it fill?

When calling EntityCommands::insert (or remove, or the bundle equivalents) repeatedly within a single system, all intermediate archetypes are constructed.

Suppose we have an entity with the component A, and call .insert(B) and .insert(C). Despite only caring about enities that have the component sets (archetypes) {A} and {A, B, C}, the archetype {A, B} is also constructed.

This has both immediate performance costs, and reduces general program performance as these empty archetypes continue to exist.

What solution would you like?

Automatically batch all component-modifying methods on EntityCommands into a single modify_bundle EntityCommand for each entity before processing them.

What alternative(s) have you considered?

Users can acheive this effect by manually grouping these calls, but this is limited to pure insertion or pure removal EntityCommands, non-obvious and can lead to less clear code.

We could do even smarter batching strategies, e.g generating spawn_batch calls, but that is a) much harder and b) less immediately important.

Additional context

This is essential to ensuring that #1481 is both usable and maintains correctness at all times, otherwise these temporary archetypes are constructed and can fail the assertions generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorC-PerformanceA change motivated by improving speed, memory usage or compile timesC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions