Skip to content

Optimize spawn_batch + relations #19891

Open
@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

    S-Needs-TriageThis issue needs to be labelled

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions