Improve Editor Inspector/Theme item lookup performance

Changes to reduce the latency between changing node selection in the editor and seeing the new node reflected in the Inspector tab

- Use Vector instead of List for ThemeOwner::get_theme_type_dependencies and related functions
- Use Vector 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%
This commit is contained in:
aaronp64
2024-06-24 10:09:20 -04:00
parent 6b281c0c07
commit 7593e55527
16 changed files with 140 additions and 115 deletions

View File

@@ -199,7 +199,7 @@ void ThemeOwner::propagate_theme_changed(Node *p_to_node, Node *p_owner_node, bo
// Theme lookup.
void ThemeOwner::get_theme_type_dependencies(const Node *p_for_node, const StringName &p_theme_type, List<StringName> *r_list) const {
void ThemeOwner::get_theme_type_dependencies(const Node *p_for_node, const StringName &p_theme_type, Vector<StringName> &r_result) const {
const Control *for_c = Object::cast_to<Control>(p_for_node);
const Window *for_w = Object::cast_to<Window>(p_for_node);
ERR_FAIL_COND_MSG(!for_c && !for_w, "Only Control and Window nodes and derivatives can be polled for theming.");
@@ -224,7 +224,7 @@ void ThemeOwner::get_theme_type_dependencies(const Node *p_for_node, const Strin
while (owner_node) {
Ref<Theme> owner_theme = _get_owner_node_theme(owner_node);
if (owner_theme.is_valid() && owner_theme->get_type_variation_base(type_variation) != StringName()) {
owner_theme->get_type_dependencies(type_name, type_variation, r_list);
owner_theme->get_type_dependencies(type_name, type_variation, r_result);
return;
}
@@ -235,21 +235,21 @@ void ThemeOwner::get_theme_type_dependencies(const Node *p_for_node, const Strin
ThemeContext *global_context = _get_active_owner_context();
for (const Ref<Theme> &theme : global_context->get_themes()) {
if (theme.is_valid() && theme->get_type_variation_base(type_variation) != StringName()) {
theme->get_type_dependencies(type_name, type_variation, r_list);
theme->get_type_dependencies(type_name, type_variation, r_result);
return;
}
}
// If nothing was found, get the native dependencies for the current class.
ThemeDB::get_singleton()->get_native_type_dependencies(type_name, r_list);
ThemeDB::get_singleton()->get_native_type_dependencies(type_name, r_result);
return;
}
// Otherwise, get the native dependencies for the provided theme type.
ThemeDB::get_singleton()->get_native_type_dependencies(p_theme_type, r_list);
ThemeDB::get_singleton()->get_native_type_dependencies(p_theme_type, r_result);
}
Variant ThemeOwner::get_theme_item_in_types(Theme::DataType p_data_type, const StringName &p_name, const List<StringName> &p_theme_types) {
Variant ThemeOwner::get_theme_item_in_types(Theme::DataType p_data_type, const StringName &p_name, const Vector<StringName> &p_theme_types) {
ERR_FAIL_COND_V_MSG(p_theme_types.is_empty(), Variant(), "At least one theme type must be specified.");
// First, look through each control or window node in the branch, until no valid parent can be found.
@@ -285,7 +285,7 @@ Variant ThemeOwner::get_theme_item_in_types(Theme::DataType p_data_type, const S
return global_context->get_fallback_theme()->get_theme_item(p_data_type, p_name, StringName());
}
bool ThemeOwner::has_theme_item_in_types(Theme::DataType p_data_type, const StringName &p_name, const List<StringName> &p_theme_types) {
bool ThemeOwner::has_theme_item_in_types(Theme::DataType p_data_type, const StringName &p_name, const Vector<StringName> &p_theme_types) {
ERR_FAIL_COND_V_MSG(p_theme_types.is_empty(), false, "At least one theme type must be specified.");
// First, look through each control or window node in the branch, until no valid parent can be found.