Skip to content

Commit 7593e55

Browse files
committed
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%
1 parent 6b281c0 commit 7593e55

16 files changed

+141
-116
lines changed

core/object/class_db.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,29 @@ StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) {
291291
return ti->inherits;
292292
}
293293

294+
bool ClassDB::get_inheritance_chain_nocheck(const StringName &p_class, Vector<StringName> &r_result) {
295+
OBJTYPE_RLOCK;
296+
297+
ClassInfo *start = classes.getptr(p_class);
298+
if (!start) {
299+
return false;
300+
}
301+
302+
int classes_to_add = 0;
303+
for (ClassInfo *ti = start; ti; ti = ti->inherits_ptr) {
304+
classes_to_add++;
305+
}
306+
307+
int64_t old_size = r_result.size();
308+
r_result.resize(old_size + classes_to_add);
309+
StringName *w = r_result.ptrw() + old_size;
310+
for (ClassInfo *ti = start; ti; ti = ti->inherits_ptr) {
311+
*w++ = ti->name;
312+
}
313+
314+
return true;
315+
}
316+
294317
StringName ClassDB::get_compatibility_remapped_class(const StringName &p_class) {
295318
if (classes.has(p_class)) {
296319
return p_class;

core/object/class_db.h

+1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ class ClassDB {
282282
static void get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
283283
static void get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
284284
static StringName get_parent_class_nocheck(const StringName &p_class);
285+
static bool get_inheritance_chain_nocheck(const StringName &p_class, Vector<StringName> &r_result);
285286
static StringName get_parent_class(const StringName &p_class);
286287
static StringName get_compatibility_remapped_class(const StringName &p_class);
287288
static bool class_exists(const StringName &p_class);

editor/editor_node.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ void EditorNode::_update_theme(bool p_skip_creation) {
487487
DisplayServer::set_early_window_clear_color_override(true, theme->get_color(SNAME("background"), EditorStringName(Editor)));
488488
}
489489

490-
List<Ref<Theme>> editor_themes;
490+
Vector<Ref<Theme>> editor_themes;
491491
editor_themes.push_back(theme);
492492
editor_themes.push_back(ThemeDB::get_singleton()->get_default_theme());
493493

@@ -556,7 +556,7 @@ void EditorNode::update_preview_themes(int p_mode) {
556556
return; // Too early.
557557
}
558558

559-
List<Ref<Theme>> preview_themes;
559+
Vector<Ref<Theme>> preview_themes;
560560

561561
switch (p_mode) {
562562
case CanvasItemEditor::THEME_PREVIEW_PROJECT:

editor/plugins/theme_editor_preview.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void ThemeEditorPreview::_notification(int p_what) {
205205
} break;
206206

207207
case NOTIFICATION_READY: {
208-
List<Ref<Theme>> preview_themes;
208+
Vector<Ref<Theme>> preview_themes;
209209
preview_themes.push_back(ThemeDB::get_singleton()->get_default_theme());
210210
ThemeDB::get_singleton()->create_theme_context(preview_root, preview_themes);
211211
} break;

editor/project_manager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void ProjectManager::_update_theme(bool p_skip_creation) {
190190
DisplayServer::set_early_window_clear_color_override(true, theme->get_color(SNAME("background"), EditorStringName(Editor)));
191191
}
192192

193-
List<Ref<Theme>> editor_themes;
193+
Vector<Ref<Theme>> editor_themes;
194194
editor_themes.push_back(theme);
195195
editor_themes.push_back(ThemeDB::get_singleton()->get_default_theme());
196196

scene/3d/label_3d.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -797,13 +797,13 @@ Ref<Font> Label3D::_get_font_or_default() const {
797797
}
798798

799799
const StringName theme_name = SceneStringName(font);
800-
List<StringName> theme_types;
801-
ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), &theme_types);
800+
Vector<StringName> theme_types;
801+
ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), theme_types);
802802

803803
ThemeContext *global_context = ThemeDB::get_singleton()->get_default_theme_context();
804-
List<Ref<Theme>> themes = global_context->get_themes();
804+
Vector<Ref<Theme>> themes = global_context->get_themes();
805805
if (Engine::get_singleton()->is_editor_hint()) {
806-
themes.push_front(ThemeDB::get_singleton()->get_project_theme());
806+
themes.insert(0, ThemeDB::get_singleton()->get_project_theme());
807807
}
808808

809809
for (const Ref<Theme> &theme : themes) {

scene/gui/control.cpp

+24-24
Original file line numberDiff line numberDiff line change
@@ -2575,8 +2575,8 @@ Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringNam
25752575
return data.theme_icon_cache[p_theme_type][p_name];
25762576
}
25772577

2578-
List<StringName> theme_types;
2579-
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2578+
Vector<StringName> theme_types;
2579+
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
25802580
Ref<Texture2D> icon = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_ICON, p_name, theme_types);
25812581
data.theme_icon_cache[p_theme_type][p_name] = icon;
25822582
return icon;
@@ -2599,8 +2599,8 @@ Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const String
25992599
return data.theme_style_cache[p_theme_type][p_name];
26002600
}
26012601

2602-
List<StringName> theme_types;
2603-
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2602+
Vector<StringName> theme_types;
2603+
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
26042604
Ref<StyleBox> style = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_STYLEBOX, p_name, theme_types);
26052605
data.theme_style_cache[p_theme_type][p_name] = style;
26062606
return style;
@@ -2623,8 +2623,8 @@ Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_
26232623
return data.theme_font_cache[p_theme_type][p_name];
26242624
}
26252625

2626-
List<StringName> theme_types;
2627-
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2626+
Vector<StringName> theme_types;
2627+
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
26282628
Ref<Font> font = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_FONT, p_name, theme_types);
26292629
data.theme_font_cache[p_theme_type][p_name] = font;
26302630
return font;
@@ -2647,8 +2647,8 @@ int Control::get_theme_font_size(const StringName &p_name, const StringName &p_t
26472647
return data.theme_font_size_cache[p_theme_type][p_name];
26482648
}
26492649

2650-
List<StringName> theme_types;
2651-
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2650+
Vector<StringName> theme_types;
2651+
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
26522652
int font_size = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_FONT_SIZE, p_name, theme_types);
26532653
data.theme_font_size_cache[p_theme_type][p_name] = font_size;
26542654
return font_size;
@@ -2671,8 +2671,8 @@ Color Control::get_theme_color(const StringName &p_name, const StringName &p_the
26712671
return data.theme_color_cache[p_theme_type][p_name];
26722672
}
26732673

2674-
List<StringName> theme_types;
2675-
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2674+
Vector<StringName> theme_types;
2675+
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
26762676
Color color = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_COLOR, p_name, theme_types);
26772677
data.theme_color_cache[p_theme_type][p_name] = color;
26782678
return color;
@@ -2695,8 +2695,8 @@ int Control::get_theme_constant(const StringName &p_name, const StringName &p_th
26952695
return data.theme_constant_cache[p_theme_type][p_name];
26962696
}
26972697

2698-
List<StringName> theme_types;
2699-
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2698+
Vector<StringName> theme_types;
2699+
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
27002700
int constant = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_CONSTANT, p_name, theme_types);
27012701
data.theme_constant_cache[p_theme_type][p_name] = constant;
27022702
return constant;
@@ -2741,8 +2741,8 @@ bool Control::has_theme_icon(const StringName &p_name, const StringName &p_theme
27412741
}
27422742
}
27432743

2744-
List<StringName> theme_types;
2745-
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2744+
Vector<StringName> theme_types;
2745+
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
27462746
return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_ICON, p_name, theme_types);
27472747
}
27482748

@@ -2758,8 +2758,8 @@ bool Control::has_theme_stylebox(const StringName &p_name, const StringName &p_t
27582758
}
27592759
}
27602760

2761-
List<StringName> theme_types;
2762-
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2761+
Vector<StringName> theme_types;
2762+
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
27632763
return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_STYLEBOX, p_name, theme_types);
27642764
}
27652765

@@ -2775,8 +2775,8 @@ bool Control::has_theme_font(const StringName &p_name, const StringName &p_theme
27752775
}
27762776
}
27772777

2778-
List<StringName> theme_types;
2779-
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2778+
Vector<StringName> theme_types;
2779+
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
27802780
return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_FONT, p_name, theme_types);
27812781
}
27822782

@@ -2792,8 +2792,8 @@ bool Control::has_theme_font_size(const StringName &p_name, const StringName &p_
27922792
}
27932793
}
27942794

2795-
List<StringName> theme_types;
2796-
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2795+
Vector<StringName> theme_types;
2796+
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
27972797
return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_FONT_SIZE, p_name, theme_types);
27982798
}
27992799

@@ -2809,8 +2809,8 @@ bool Control::has_theme_color(const StringName &p_name, const StringName &p_them
28092809
}
28102810
}
28112811

2812-
List<StringName> theme_types;
2813-
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2812+
Vector<StringName> theme_types;
2813+
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
28142814
return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_COLOR, p_name, theme_types);
28152815
}
28162816

@@ -2826,8 +2826,8 @@ bool Control::has_theme_constant(const StringName &p_name, const StringName &p_t
28262826
}
28272827
}
28282828

2829-
List<StringName> theme_types;
2830-
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2829+
Vector<StringName> theme_types;
2830+
data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
28312831
return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_CONSTANT, p_name, theme_types);
28322832
}
28332833

scene/main/window.cpp

+24-24
Original file line numberDiff line numberDiff line change
@@ -2159,8 +2159,8 @@ Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName
21592159
return theme_icon_cache[p_theme_type][p_name];
21602160
}
21612161

2162-
List<StringName> theme_types;
2163-
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2162+
Vector<StringName> theme_types;
2163+
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
21642164
Ref<Texture2D> icon = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_ICON, p_name, theme_types);
21652165
theme_icon_cache[p_theme_type][p_name] = icon;
21662166
return icon;
@@ -2183,8 +2183,8 @@ Ref<StyleBox> Window::get_theme_stylebox(const StringName &p_name, const StringN
21832183
return theme_style_cache[p_theme_type][p_name];
21842184
}
21852185

2186-
List<StringName> theme_types;
2187-
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2186+
Vector<StringName> theme_types;
2187+
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
21882188
Ref<StyleBox> style = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_STYLEBOX, p_name, theme_types);
21892189
theme_style_cache[p_theme_type][p_name] = style;
21902190
return style;
@@ -2207,8 +2207,8 @@ Ref<Font> Window::get_theme_font(const StringName &p_name, const StringName &p_t
22072207
return theme_font_cache[p_theme_type][p_name];
22082208
}
22092209

2210-
List<StringName> theme_types;
2211-
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2210+
Vector<StringName> theme_types;
2211+
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
22122212
Ref<Font> font = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_FONT, p_name, theme_types);
22132213
theme_font_cache[p_theme_type][p_name] = font;
22142214
return font;
@@ -2231,8 +2231,8 @@ int Window::get_theme_font_size(const StringName &p_name, const StringName &p_th
22312231
return theme_font_size_cache[p_theme_type][p_name];
22322232
}
22332233

2234-
List<StringName> theme_types;
2235-
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2234+
Vector<StringName> theme_types;
2235+
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
22362236
int font_size = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_FONT_SIZE, p_name, theme_types);
22372237
theme_font_size_cache[p_theme_type][p_name] = font_size;
22382238
return font_size;
@@ -2255,8 +2255,8 @@ Color Window::get_theme_color(const StringName &p_name, const StringName &p_them
22552255
return theme_color_cache[p_theme_type][p_name];
22562256
}
22572257

2258-
List<StringName> theme_types;
2259-
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2258+
Vector<StringName> theme_types;
2259+
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
22602260
Color color = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_COLOR, p_name, theme_types);
22612261
theme_color_cache[p_theme_type][p_name] = color;
22622262
return color;
@@ -2279,8 +2279,8 @@ int Window::get_theme_constant(const StringName &p_name, const StringName &p_the
22792279
return theme_constant_cache[p_theme_type][p_name];
22802280
}
22812281

2282-
List<StringName> theme_types;
2283-
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2282+
Vector<StringName> theme_types;
2283+
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
22842284
int constant = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_CONSTANT, p_name, theme_types);
22852285
theme_constant_cache[p_theme_type][p_name] = constant;
22862286
return constant;
@@ -2325,8 +2325,8 @@ bool Window::has_theme_icon(const StringName &p_name, const StringName &p_theme_
23252325
}
23262326
}
23272327

2328-
List<StringName> theme_types;
2329-
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2328+
Vector<StringName> theme_types;
2329+
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
23302330
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_ICON, p_name, theme_types);
23312331
}
23322332

@@ -2342,8 +2342,8 @@ bool Window::has_theme_stylebox(const StringName &p_name, const StringName &p_th
23422342
}
23432343
}
23442344

2345-
List<StringName> theme_types;
2346-
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2345+
Vector<StringName> theme_types;
2346+
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
23472347
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_STYLEBOX, p_name, theme_types);
23482348
}
23492349

@@ -2359,8 +2359,8 @@ bool Window::has_theme_font(const StringName &p_name, const StringName &p_theme_
23592359
}
23602360
}
23612361

2362-
List<StringName> theme_types;
2363-
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2362+
Vector<StringName> theme_types;
2363+
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
23642364
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_FONT, p_name, theme_types);
23652365
}
23662366

@@ -2376,8 +2376,8 @@ bool Window::has_theme_font_size(const StringName &p_name, const StringName &p_t
23762376
}
23772377
}
23782378

2379-
List<StringName> theme_types;
2380-
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2379+
Vector<StringName> theme_types;
2380+
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
23812381
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_FONT_SIZE, p_name, theme_types);
23822382
}
23832383

@@ -2393,8 +2393,8 @@ bool Window::has_theme_color(const StringName &p_name, const StringName &p_theme
23932393
}
23942394
}
23952395

2396-
List<StringName> theme_types;
2397-
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2396+
Vector<StringName> theme_types;
2397+
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
23982398
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_COLOR, p_name, theme_types);
23992399
}
24002400

@@ -2410,8 +2410,8 @@ bool Window::has_theme_constant(const StringName &p_name, const StringName &p_th
24102410
}
24112411
}
24122412

2413-
List<StringName> theme_types;
2414-
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2413+
Vector<StringName> theme_types;
2414+
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
24152415
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_CONSTANT, p_name, theme_types);
24162416
}
24172417

scene/resources/3d/primitive_meshes.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -3468,13 +3468,13 @@ Ref<Font> TextMesh::_get_font_or_default() const {
34683468
}
34693469

34703470
StringName theme_name = "font";
3471-
List<StringName> theme_types;
3472-
ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), &theme_types);
3471+
Vector<StringName> theme_types;
3472+
ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), theme_types);
34733473

34743474
ThemeContext *global_context = ThemeDB::get_singleton()->get_default_theme_context();
3475-
List<Ref<Theme>> themes = global_context->get_themes();
3475+
Vector<Ref<Theme>> themes = global_context->get_themes();
34763476
if (Engine::get_singleton()->is_editor_hint()) {
3477-
themes.push_front(ThemeDB::get_singleton()->get_project_theme());
3477+
themes.insert(0, ThemeDB::get_singleton()->get_project_theme());
34783478
}
34793479

34803480
for (const Ref<Theme> &theme : themes) {

0 commit comments

Comments
 (0)