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

Speed up the "is node in tree" check when loading a scene or bypass it in release builds #2367

Open
TrickMe opened this issue Feb 27, 2021 · 2 comments

Comments

@TrickMe
Copy link

TrickMe commented Feb 27, 2021

Describe the project you are working on

Realtime space x4 with potentially dozens of thousand nodes.

Describe the problem or limitation you are having in your project

Initial loading of the space scene takes exponential time, based on how much nodes are added to the tree.
2x nodes means about 4x the initial loading time.
Adding a new fleet or fleets to the tree also takes longer if more nodes are in the tree.

I think the core of the problem is that with .add_child(newNode) newNode is checked against every node currently in tree.
I haven't looked up the source code, but that would explain the exponential loading time growth.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

solutions:
1:
add a bool to the node class, which indicates if the node is in tree and can be checked instead of checking every node in the whole tree.
This would eliminate the exponential growth in loading time.

2:
Only check if newNode is in tree in debug, but not in release build.

3:
add a boolean to the add_child() function to set if the node should be checked against in-tree nodes.
eg: add_child(newNode, false, false)

If this enhancement will not be used often, can it be worked around with a few lines of script?

I have not found a workaround at all.

Is there a reason why this should be core and not an add-on in the asset library?

Strategy games regularly use a high number of nodes in the tree, so i think it would be beneficial to the engine and its users.

edit:
adding new ships/fleets actually takes linearly longer depending on the number of nodes in the tree, but for adding single nodes it shouldn't matter how many nodes are in the tree, so it's still an issue.

edit2:
queue_free(), call_deferred("free") and probably get_tree().change_scene() ,get_tree().change_scene_to() effected as well.
Removed "#" in solutions.

@Calinou Calinou changed the title faster "is node in tree" check or bypass Speed up the "is node in tree" check when loading a scene or bypass it in release builds Feb 27, 2021
@Riteo
Copy link

Riteo commented Mar 2, 2021

I would be ok if this is it were somehow limited only to loading. I'm pretty sure that runtime checking is needed, since you don't want duplicate node names.

@TrickMe
Copy link
Author

TrickMe commented Mar 3, 2021

The issue also effects queue_free() and call_deferred("free")
Probably also get_tree().change_scene() and get_tree().change_scene_to()

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

No branches or pull requests

3 participants