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

Improve Editor Inspector/Theme item lookup performance #93602

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aaronp64
Copy link
Contributor

@aaronp64 aaronp64 commented Jun 25, 2024

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%. 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.

p_list->push_back(class_name);
class_name = ClassDB::get_parent_class_nocheck(class_name);
}
r_result.reserve(8);
Copy link
Contributor

@Mickeon Mickeon Jun 26, 2024

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

Copy link
Member

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

Copy link
Contributor

@Mickeon Mickeon Jun 26, 2024

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.

Copy link
Contributor Author

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).

Copy link
Contributor Author

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%
Copy link
Contributor

@Mickeon Mickeon left a 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.

scene/resources/theme.cpp Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants