Skip to content

[3.x] Change Node children to use LocalVector #107544

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

Merged
merged 1 commit into from
Jun 18, 2025

Conversation

lawnjelly
Copy link
Member

@lawnjelly lawnjelly commented Jun 14, 2025

There is no need for COW, it will only slow Node down.

LocalVectori (signed) rather than LocalVector

One gotcha when changing between Vector and LocalVector is that the default size for LocalVector is unsigned, and Vector is signed. Usually unsigned makes more sense for counters, but in this case, children is used in quite a lot of code in Node and in the interests of not introducing any new bugs, I have just changed it to the signed variation of LocalVector.

If we desire to change to unsigned LocalVector, that is probably best as a follow up, then modify the counters etc in Node.cpp.

Notes

  • First commit is [3.x] Remove implicit conversion from LocalVector to Vector #107543, as we are using explicit LocalVector to detect any expensive conversions (there were none).
  • Only 4 lines of code needed, may give some speedup as there in no COW machinery needed, and Node children are used a lot.
  • As with Spatial children and CanvasItem children, really should have converted these when we created LocalVector, but hey, better late than never. 😁
  • This is 3.x specific, 4.x uses different containers for storing Node children.

@lawnjelly lawnjelly added this to the 3.7 milestone Jun 14, 2025
@lawnjelly lawnjelly requested review from a team as code owners June 14, 2025 19:00
@lawnjelly lawnjelly marked this pull request as draft June 14, 2025 19:15
@lawnjelly lawnjelly force-pushed the node_children_localvector branch from a56c4f6 to 079f74e Compare June 15, 2025 06:22
@lawnjelly lawnjelly marked this pull request as ready for review June 15, 2025 06:26
There is no need for COW, it will only slow `Node` down.
@lawnjelly lawnjelly force-pushed the node_children_localvector branch from 079f74e to e208003 Compare June 18, 2025 13:40
Copy link
Member

@Ivorforce Ivorforce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to comment that get_children will now need to create a copy, but it actually already does because it needs to return an Array. Makes sense 😅
As far as I can see the CoW property of children is never used, so LocalVector makes more sense.

Note that LocalVector never shrinks, as opposed to Vector, so this may start zombying memory. This may not be a problem because it's unlikely a Node will be used by adding thousands of children, only to shrink and never have them again. But it's good to keep in mind; we may want to use hysteresis shrinking in later iterations.

@lawnjelly
Copy link
Member Author

Yup as discussed on RC, it is likely worth using hysteresis for Node, Spatial and CanvasItem children. 👍

@lawnjelly lawnjelly merged commit 6645716 into godotengine:3.x Jun 18, 2025
25 of 28 checks passed
@lawnjelly lawnjelly deleted the node_children_localvector branch June 18, 2025 16:20
@lawnjelly
Copy link
Member Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants