-
-
Notifications
You must be signed in to change notification settings - Fork 22.8k
[3.x] Spatial
and CanvasItem
children change to LocalVector
#107480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3.x] Spatial
and CanvasItem
children change to LocalVector
#107480
Conversation
Spatial
children from linked list to linearSpatial
children from linked list to vector
87b1be2
to
b459fd5
Compare
Spatial
children from linked list to vectorSpatial
and CanvasItem
children change to LocalVector
struct Data { | ||
LocalVector<CanvasItem *> children; | ||
uint32_t parent_child_id = UINT32_MAX; | ||
} data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should likely move all CanvasItem
data into a Data
struct as we do with Spatial
and Node
, to prevent name conflicts and subtle bugs. But this is for a follow up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me. LocalVector
should be a straight upgrade over List
for this use-case.
Code looks good to me, just two comments on this.
edb7252
to
97ed666
Compare
scene/3d/spatial.cpp
Outdated
uint32_t c = data.index_in_parent; | ||
LocalVector<Spatial *> &parent_children = data.parent->data.children; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I prefer not creating aliases if they aren't performance critical or change semantical meaning, because then you'll have to remember less information reading the code top to bottom.
But that's not critical, feel free to leave as is if you prefer the other way.
97ed666
to
8e48d57
Compare
Thanks! |
Spatial
maintains its own list ofSpatial
-only children (separate from theNode
), in order to (in theory) make child iteration faster for only spatial children. The same happens withCanvasItem
andCanvasItem
children.The problem is that these lists are stored as a linked list, and there is no reason to require linked list. Linked lists are bad for cache.
Benchmark
benchmark_spatial_children.zip
before: 157 fps
after: 280 fps
The benchmark creates a large number of
Spatial
children to the root node, then rotates the root. This stresses the_propagate_transform_changed()
which utilizes the children list.Notes
Spatial
children list entirely and utilizing theNode
children list instead with fast casting, but this PR is still faster (because of no need for cast checks).NULL
checks in the original were redundant, I don't think these pointers can beNULL
given the code here.SceneTreeFTI
now it is faster, instead ofNode
children. Not 100% on this yet, but worth looking into.CanvasItem
, the same applies.