Skip to content

Add queue_free_children and free_children#117136

Open
shoyguer wants to merge 3 commits intogodotengine:masterfrom
shoyguer:feature/free_children
Open

Add queue_free_children and free_children#117136
shoyguer wants to merge 3 commits intogodotengine:masterfrom
shoyguer:feature/free_children

Conversation

@shoyguer
Copy link

@shoyguer shoyguer commented Mar 6, 2026

Closes godotengine/godot-proposals#764.
Related to #94163.
Co-authored-by: @radiantgurl

I added:

  • Add free_children() to Node class
  • Add queue_free_children() to Node class

Optimization test

Testing of speed using 1000 children iterating for 500 times.

free_children() (in tree)
  Manual loop:     386.574 ms
  Native loop:       148.931 ms
  Speedup:         2.60x

queue_free_children() (in tree)
  Manual loop:     92.189 ms
  Native loop:       32.323 ms
  Speedup:         2.85x

free_children() (not in tree)
  Manual loop:     238.888 ms
  Native loop:       137.957 ms
  Speedup:         1.73x

queue_free_children() (not in tree)
  Manual loop:     92.856 ms
  Native loop:       36.007 ms
  Speedup:         2.58x

As you can see, the free_children() on the "not in tree" gain is slower, and it is because the standalone path skips most SceneTree overhead already, runtime then leans on per-child memdelete cost, and relative gain ends lower than in-tree path.

PC build for testing:

Windows 11
AMD Ryzen 5 5600
AMD RX 6750XT 12GB
48GB RAM 3200MHz
SSD M.2 512GB

@Nintorch Nintorch added this to the 4.x milestone Mar 6, 2026
@Nintorch Nintorch requested a review from a team March 6, 2026 05:52
@AThousandShips AThousandShips changed the title Add queue_free_children and free_children Add queue_free_children and free_children Mar 6, 2026
@AThousandShips

This comment was marked as resolved.

Co-authored-by: radiantgurl <69520693+RadiantUwU@users.noreply.github.com>
@shoyguer
Copy link
Author

shoyguer commented Mar 6, 2026

@AThousandShips , done

@shoyguer shoyguer marked this pull request as ready for review March 6, 2026 20:39
@shoyguer shoyguer requested a review from a team as a code owner March 6, 2026 20:39
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.

Add a way to remove all children from a node quickly

4 participants