Skip to content

Optimize spawn_batch + relations #19891

@alice-i-cecile

Description

@alice-i-cecile

@chescock in #19519 (comment)_ says:

With this change, every branch in this hook (after the RelationshipHookMode check) is guaranteed to run a command, right? It might make sense as a follow-up PR to wrap the entire method in world.commands.queue(|world| {...}). That would avoid having to look up target_entity twice, which would also avoid the possibility of it getting despawned in between.

Huh, and it also looks like EntityEntryCommands::or_insert_with just invokes the closure immediately. If we work with world instead of commands then I think we can avoid allocating a new RelationshipTarget if it already exists. Also, I'm going to create an issue for or_insert_with, because that behavior is surprising ... #19884.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-PerformanceA change motivated by improving speed, memory usage or compile times

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions