bevyengine / bevyengine/bevy

Optimize spawn_batch + relations

Open
#19,891 3 comments 0 reactions 0 assignees View on GitHub
A-ECS C-Performance
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

@chescock in https://github.com/bevyengine/bevy/pull/19519#discussion_r2175180498_ 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.