Skip to content

Commit f4f1471

Browse files
committed
Merge pull request #105910 from lawnjelly/global_get_fast4
Add `GLOBAL_GET` cached macros.
2 parents d7615dc + f8f350a commit f4f1471

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+110
-77
lines changed

core/config/project_settings.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
296296
for (int i = 0; i < custom_feature_array.size(); i++) {
297297
custom_features.insert(custom_feature_array[i]);
298298
}
299+
300+
_version++;
299301
_queue_changed();
300302
return true;
301303
}
@@ -341,6 +343,7 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
341343
}
342344
}
343345

346+
_version++;
344347
_queue_changed();
345348
return true;
346349
}

core/config/project_settings.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ class ProjectSettings : public Object {
4242

4343
bool is_changed = false;
4444

45+
// Starting version from 1 ensures that all callers can reset their tested version to 0,
46+
// and will always detect the initial project settings as a "change".
47+
uint32_t _version = 1;
48+
4549
public:
4650
typedef HashMap<String, Variant> CustomMap;
4751
static inline const String PROJECT_DATA_DIR_NAME_SUFFIX = "godot";
@@ -218,6 +222,9 @@ class ProjectSettings : public Object {
218222
String get_scene_groups_cache_path() const;
219223
void load_scene_groups_cache();
220224

225+
// Testing a version allows fast cached GET_GLOBAL macros.
226+
uint32_t get_version() const { return _version; }
227+
221228
#ifdef TOOLS_ENABLED
222229
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
223230
#endif
@@ -243,3 +250,26 @@ Variant _GLOBAL_DEF(const PropertyInfo &p_info, const Variant &p_default, bool p
243250
#define GLOBAL_DEF_RST_NOVAL_BASIC(m_var, m_value) _GLOBAL_DEF(m_var, m_value, true, true, true)
244251

245252
#define GLOBAL_DEF_INTERNAL(m_var, m_value) _GLOBAL_DEF(m_var, m_value, false, false, false, true)
253+
254+
/////////////////////////////////////////////////////////////////////////////////////////
255+
// Cached versions of GLOBAL_GET.
256+
// Cached but uses a typed variable for storage, this can be more efficient.
257+
// Variables prefixed with _ggc_ to avoid shadowing warnings.
258+
#define GLOBAL_GET_CACHED(m_type, m_setting_name) ([](const char *p_name) -> m_type {\
259+
static_assert(std::is_trivially_destructible<m_type>::value, "GLOBAL_GET_CACHED must use a trivial type that allows static lifetime.");\
260+
static m_type _ggc_local_var;\
261+
static uint32_t _ggc_local_version = 0;\
262+
static SpinLock _ggc_spin;\
263+
uint32_t _ggc_new_version = ProjectSettings::get_singleton()->get_version();\
264+
if (_ggc_local_version != _ggc_new_version) {\
265+
_ggc_spin.lock();\
266+
_ggc_local_version = _ggc_new_version;\
267+
_ggc_local_var = ProjectSettings::get_singleton()->get_setting_with_override(p_name);\
268+
m_type _ggc_temp = _ggc_local_var;\
269+
_ggc_spin.unlock();\
270+
return _ggc_temp;\
271+
}\
272+
_ggc_spin.lock();\
273+
m_type _ggc_temp2 = _ggc_local_var;\
274+
_ggc_spin.unlock();\
275+
return _ggc_temp2; })(m_setting_name)

drivers/gles3/rasterizer_gles3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void RasterizerGLES3::begin_frame(double frame_step) {
100100

101101
time_total += frame_step;
102102

103-
double time_roll_over = GLOBAL_GET("rendering/limits/time/time_rollover_secs");
103+
double time_roll_over = GLOBAL_GET_CACHED(double, "rendering/limits/time/time_rollover_secs");
104104
time_total = Math::fmod(time_total, time_roll_over);
105105

106106
canvas->set_time(time_total);

editor/editor_help.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4532,7 +4532,7 @@ Control *EditorHelpBitTooltip::show_tooltip(Control *p_target, const String &p_s
45324532
// Copy-paste from `Viewport::_gui_show_tooltip()`.
45334533
void EditorHelpBitTooltip::popup_under_cursor() {
45344534
Point2 mouse_pos = get_mouse_position();
4535-
Point2 tooltip_offset = GLOBAL_GET("display/mouse_cursor/tooltip_position_offset");
4535+
Point2 tooltip_offset = GLOBAL_GET_CACHED(Point2, "display/mouse_cursor/tooltip_position_offset");
45364536
Rect2 r(mouse_pos + tooltip_offset, get_contents_minimum_size());
45374537
r.size = r.size.min(get_max_size());
45384538

editor/editor_locale_dialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ void EditorLocaleDialog::_update_tree() {
242242

243243
int filter = SHOW_ALL_LOCALES;
244244
if (ProjectSettings::get_singleton()->has_setting("internationalization/locale/locale_filter_mode")) {
245-
filter = GLOBAL_GET("internationalization/locale/locale_filter_mode");
245+
filter = GLOBAL_GET_CACHED(int, "internationalization/locale/locale_filter_mode");
246246
}
247247
Array f_lang_all;
248248
if (ProjectSettings::get_singleton()->has_setting("internationalization/locale/language_filter")) {

modules/fbx/editor/editor_scene_importer_ufbx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Node *EditorSceneFormatImporterUFBX::import_scene(const String &p_path, uint32_t
4343
const HashMap<StringName, Variant> &p_options,
4444
List<String> *r_missing_deps, Error *r_err) {
4545
// FIXME: Hack to work around GH-86309.
46-
if (p_options.has("fbx/importer") && int(p_options["fbx/importer"]) == FBX_IMPORTER_FBX2GLTF && GLOBAL_GET("filesystem/import/fbx2gltf/enabled")) {
46+
if (p_options.has("fbx/importer") && int(p_options["fbx/importer"]) == FBX_IMPORTER_FBX2GLTF && GLOBAL_GET_CACHED(bool, "filesystem/import/fbx2gltf/enabled")) {
4747
Ref<EditorSceneFormatImporterFBX2GLTF> fbx2gltf_importer;
4848
fbx2gltf_importer.instantiate();
4949
Node *scene = fbx2gltf_importer->import_scene(p_path, p_flags, p_options, r_missing_deps, r_err);

modules/gdscript/gdscript_analyzer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3701,7 +3701,7 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a
37013701
String base_name = is_self && !p_call->is_super ? "self" : base_type.to_string();
37023702
#ifdef SUGGEST_GODOT4_RENAMES
37033703
String rename_hint;
3704-
if (GLOBAL_GET("debug/gdscript/warnings/renamed_in_godot_4_hint")) {
3704+
if (GLOBAL_GET_CACHED(bool, "debug/gdscript/warnings/renamed_in_godot_4_hint")) {
37053705
const char *renamed_function_name = check_for_renamed_identifier(p_call->function_name, p_call->type);
37063706
if (renamed_function_name) {
37073707
rename_hint = " " + vformat(R"(Did you mean to use "%s"?)", String(renamed_function_name) + "()");
@@ -4048,7 +4048,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod
40484048
if (!valid && base.is_hard_type()) {
40494049
#ifdef SUGGEST_GODOT4_RENAMES
40504050
String rename_hint;
4051-
if (GLOBAL_GET("debug/gdscript/warnings/renamed_in_godot_4_hint")) {
4051+
if (GLOBAL_GET_CACHED(bool, "debug/gdscript/warnings/renamed_in_godot_4_hint")) {
40524052
const char *renamed_identifier_name = check_for_renamed_identifier(name, p_identifier->type);
40534053
if (renamed_identifier_name) {
40544054
rename_hint = " " + vformat(R"(Did you mean to use "%s"?)", renamed_identifier_name);
@@ -4092,7 +4092,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod
40924092
if (base.is_hard_type()) {
40934093
#ifdef SUGGEST_GODOT4_RENAMES
40944094
String rename_hint;
4095-
if (GLOBAL_GET("debug/gdscript/warnings/renamed_in_godot_4_hint")) {
4095+
if (GLOBAL_GET_CACHED(bool, "debug/gdscript/warnings/renamed_in_godot_4_hint")) {
40964096
const char *renamed_identifier_name = check_for_renamed_identifier(name, p_identifier->type);
40974097
if (renamed_identifier_name) {
40984098
rename_hint = " " + vformat(R"(Did you mean to use "%s"?)", renamed_identifier_name);
@@ -4608,7 +4608,7 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_ident
46084608
// Not found.
46094609
#ifdef SUGGEST_GODOT4_RENAMES
46104610
String rename_hint;
4611-
if (GLOBAL_GET("debug/gdscript/warnings/renamed_in_godot_4_hint")) {
4611+
if (GLOBAL_GET_CACHED(bool, "debug/gdscript/warnings/renamed_in_godot_4_hint")) {
46124612
const char *renamed_identifier_name = check_for_renamed_identifier(name, p_identifier->type);
46134613
if (renamed_identifier_name) {
46144614
rename_hint = " " + vformat(R"(Did you mean to use "%s"?)", renamed_identifier_name);

modules/gdscript/gdscript_parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void GDScriptParser::push_warning(const Node *p_source, GDScriptWarning::Code p_
196196
if (is_ignoring_warnings) {
197197
return;
198198
}
199-
if (GLOBAL_GET("debug/gdscript/warnings/exclude_addons") && script_path.begins_with("res://addons/")) {
199+
if (GLOBAL_GET_CACHED(bool, "debug/gdscript/warnings/exclude_addons") && script_path.begins_with("res://addons/")) {
200200
return;
201201
}
202202
GDScriptWarning::WarnLevel warn_level = (GDScriptWarning::WarnLevel)(int)GLOBAL_GET(GDScriptWarning::get_settings_path_from_code(p_code));

modules/gltf/editor/editor_scene_importer_blend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ static bool _test_blender_path(const String &p_path, String *r_err = nullptr) {
374374
}
375375

376376
bool EditorFileSystemImportFormatSupportQueryBlend::is_active() const {
377-
bool blend_enabled = GLOBAL_GET("filesystem/import/blender/enabled");
377+
bool blend_enabled = GLOBAL_GET_CACHED(bool, "filesystem/import/blender/enabled");
378378

379379
if (blend_enabled && !_test_blender_path(EDITOR_GET("filesystem/import/blender/blender_path").operator String())) {
380380
// Intending to import Blender, but blend not configured.

modules/openxr/extensions/openxr_eye_gaze_interaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ HashMap<String, bool *> OpenXREyeGazeInteractionExtension::get_requested_extensi
5656

5757
// Only enable this extension when requested.
5858
// We still register our meta data or the action map editor will fail.
59-
if (GLOBAL_GET("xr/openxr/extensions/eye_gaze_interaction") && (!OS::get_singleton()->has_feature("mobile") || OS::get_singleton()->has_feature(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME))) {
59+
if (GLOBAL_GET_CACHED(bool, "xr/openxr/extensions/eye_gaze_interaction") && (!OS::get_singleton()->has_feature("mobile") || OS::get_singleton()->has_feature(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME))) {
6060
request_extensions[XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME] = &available;
6161
}
6262

0 commit comments

Comments
 (0)