Skip to content
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

Implement Node custom iterator for traversing children #42052

Closed
wants to merge 1 commit into from
Closed

Implement Node custom iterator for traversing children #42052

wants to merge 1 commit into from

Conversation

Xrayez
Copy link
Contributor

@Xrayez Xrayez commented Sep 14, 2020

This PR is created as a minimal example implementation to demonstrate performance issues with using custom iterators in C++ as described in #42053.

Allows to iterate children with a plain for loop without using Node.get_children():

extends Node2D

func _ready():
	for child in $node:
		print(child)

Unfortunately, performs 10 times worse than allocating an array from get_children() and iterating it (even with 100000 nodes).

On a side note, I think this could be improved to the point that using a built-in custom iterator in C++ (#7225) could prove to be faster than current way of traversing children with get_children(), and this could be potentially in alignment to how it's currently possible to for i in number without allocating array for similar reasons, and obviously this would apply to any other custom data structure, such as linked list.

Allows to iterate children with a plain `for` loop.

Unfortunately, performs worse than allocating `get_children()`
and iterating it.
@Calinou Calinou added this to the 4.0 milestone Sep 14, 2020
@Xrayez Xrayez changed the title Implement custom iterator for Node Implement Node custom iterator for traversing children Sep 14, 2020
@Xrayez
Copy link
Contributor Author

Xrayez commented Nov 23, 2020

This PR was created to demonstrate performance issues with #42053, so closing, you'll still be able to compile the PR if you need to test this.

@Xrayez Xrayez closed this Nov 23, 2020
@Calinou Calinou removed this from the 4.0 milestone Nov 23, 2020
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