-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Bevy version
0.15, has existed for as long as constructing Parent and Children has been locked down.
What you did
Attempt to optimize spawning large batches of children in a custom command for big_space.
What went wrong
Profiling shows that applying system commands dominates system time. Spawning 320k entities took 31s.
The problem appears to be that even when spawning a brand new entity, bevy is doing reparenting checks for every child when its Parent component is added, and again for every child when the children are added to the parent entity's Children component. These checks are completely unnecessary - the entities are new and cannot yet exist in the hierarchy.
By doing some transmute shenanigans, I was able to see what a niave solution would look like if I could simply construct the Parent and Children entities myself. The performance improvement was stark: what previously took 31s now took 83ms.
I was also able to work around this without unsafe by using reflection to construct a Parent and Children, bypassing the private constructors.