-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
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
Improve Tree
performance
#94748
Improve Tree
performance
#94748
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally, it works as expected.
Testing project: test-tree.zip
Benchmark
Using an optimized editor build (MSVC 2022 optimize=speed
). Running the MRP above which contains the first code sample from OP.
Before | After |
---|---|
745 ms | 38 ms |
PC specifications
- CPU: Intel Core i9-13900K
- GPU: NVIDIA GeForce RTX 4090
- RAM: 64 GB (2×32 GB DDR5-5800 C30)
- SSD: Solidigm P44 Pro 2 TB
- OS: Windows 11 23H2
tests/test_main.cpp
Outdated
@@ -121,6 +121,7 @@ | |||
#include "tests/scene/test_sprite_frames.h" | |||
#include "tests/scene/test_theme.h" | |||
#include "tests/scene/test_timer.h" | |||
#include "tests/scene/test_tree.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be moved down to the #ifndef ADVANCED_GUI_DISABLED
part as it is advanced UI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to advanced gui section
Such a shame this came too late for 4.3; speed improvements to scene addition across the board like this are a huge help to those developing/attempting larger titles with Godot. Thanks for finding this. |
Added TreeItem::last_child to avoid needing to iterate through all children to get to the end. This mainly helps in cases where one TreeItem has many children (1000s), and new children are added to the end, as each add had to iterate through all previously added children.
It can probably be cherrypicked later, assuming lack of unforeseen consequences |
Wouldn't this fix #94648 (comment) along with rthe closing pr? |
No, I ran into this when looking into that issue, but most of the time spent in that case is in |
Thanks! |
This broke trees in at least Edit: Fixed, see: |
Added
TreeItem::last_child
to avoid needing to iterate through all children to get to the end. This mainly helps in cases where oneTreeItem
has many children (1000s), and new children are added to the end, as each add had to iterate through all previously added children.Gdscript example to compare creating
TreeItem
s, time reduced from 1640ms to 66ms:This also impacts
SceneTreeEditor
. I created aNode2D
scene with 10,000 emptyNode2D
children to test with. Opening this scene took 4.28 seconds before this change, 1.55 seconds after. At 20,000 children, time was reduced from 16 seconds to 2.65 seconds.EditorDebuggerTree
has similar slowness in adding items, but also is repeatedly updated when running game from the editor. Using the gdscript below to create 30,000Node2D
s at runtime, the editor is significantly more responsive when using the remote scene tree while the parent node stays collapsed. Once the parent node is expanded, more time is spent handling the tree's text/heights, which gets pretty slow, but is still faster than before.Also added some unit tests. All tests pass with both old and new code, except for the
Clear items
test, which failed on old code due tochildren_cache
not being cleared inclear_children()
. Looks like we avoided needing to use the cache in existing code whereclear_children()
is called, so this hasn't been an issue.