-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
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 Editor Inspector/Theme item lookup performance #93602
base: master
Are you sure you want to change the base?
Conversation
1c22737
to
7fb3982
Compare
scene/theme/theme_db.cpp
Outdated
p_list->push_back(class_name); | ||
class_name = ClassDB::get_parent_class_nocheck(class_name); | ||
} | ||
r_result.reserve(8); |
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.
How was this 8
chosen? An arbitrary number may be troublesome
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.
It's just reserving, it doesn't change anything except worsening performance if the guess is wrong
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.
In that case wouldn't it be better to reserve memory in the new ClassDB::get_parent_classes_nocheck
? I know it sounds odd but ClassDB would "know" better (if someone decided to expand the code). Makes the intent more clear, too.
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.
8's just an estimate of how many classes might be added, ideally a little higher than needed but it should be fine if it needs to grow past that in some cases. It's mainly to avoid a bunch of small allocations for 1/2/4 items in the vector. It's based on how many are expected to be added by ClassDB
, so agreed on moving it there.
Ideally, it would still be reserved before adding p_base_type
, which might not be in ClassDB
, so could be unexpected to always add it in there. Might shuffle things around a bit to make ClassDB::get_parent_classes_nocheck
match up better with ClassDB::is_parent_class
(include the passed in class if it's found), and have ThemeDB::get_native_type_dependencies
add p_base_type
when needed (if ClassDB
doesn't find it).
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.
Made the changes above and renamed get_parent_classes_nocheck
to get_inheritance_chain_nocheck
, the old name felt confusing since the starting class is now included.
Changes to reduce the latency between changing node selection in the editor and seeing the new node reflected in the Inspector tab - Use LocalVector instead of List for ThemeOwner::get_theme_type_dependencies and related functions - Use LocalVector instead of List for ThemeContext::themes, set_themes(), and get_themes() - Add ClassDB:get_inheritance_chain_nocheck to get all parent/ancestor classes at once, to avoid repeated ClassDB locking overhead - Update BIND_THEME_ITEM macros and ThemeDB::update_class_instance_items to use provided StringNames for call to ThemeItemSetter, instead of creating a new StringName in each call These changes reduce the time taken by EditorInspector::update_tree by around 30-35%
7fb3982
to
83f69f2
Compare
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.
Could use some testing but the code change is surprisingly straightforward.
Changes to reduce the latency between changing node selection in the editor and seeing the new node reflected in the Inspector tab
LocalVector
instead ofList
forThemeOwner::get_theme_type_dependencies
and related functionsLocalVector
instead ofList
forThemeContext::themes
,set_themes()
, andget_themes()
ClassDB:get_inheritance_chain_nocheck
to get all parent/ancestor classes at once, to avoid repeatedClassDB
locking overheadBIND_THEME_ITEM
macros andThemeDB::update_class_instance_items
to use providedStringNames
for call toThemeItemSetter
, instead of creating a newStringName
in each callThese changes reduce the time taken by
EditorInspector::update_tree
by around 30-35%. This should noticeably improve the delays/freezes in #93402, though there's still a lot going on when updating the Inspector. Still could be slow for some nodes, and would depend on CPU.