Implement Node
custom iterator for traversing children
#42052
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 usingNode.get_children()
: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 tofor i in number
without allocating array for similar reasons, and obviously this would apply to any other custom data structure, such as linked list.