From 3be7f5e82873417afb4bc4bc8548f1318e15c263 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Mon, 30 Nov 2026 11:32:38 +0100 Subject: [PATCH] perf: the settings static without MSVC's thread-safe initialisation check Global (GetGlobalSettings()) is a function-local static, read everywhere all the time: 1.3% of the main thread was the function itself, MSVC's check of the thread-safe initialisation reading the thread's epoch from the TLS on every call. utilities/Globals.cpp is now built with /Zc:threadSafeInit- (and without the precompiled header, which is built with the default): the static is made once, by the main thread at the start, before any other thread runs, and is only read afterwards, so the plain check of the static is enough. It's the only function-local static of the file. MSVC only. 600 s in --test, seed 12345, one run each: Tomaszewo sim 115.7 s against 117.3 s the step before (-1.4%); L107 14.9 s against 16.1 s (-7%). The physics logs (14 and 9) and the event logs are byte-identical to staging's, unit tests 1207/1207 with exact golden traces. --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 561bbc127..166bc5107 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -483,6 +483,13 @@ set(SOURCES set(DEFINITIONS) set(SOURCES ${SOURCES} "imgui/imgui_impl_opengl3.cpp") set_source_files_properties("imgui/imgui_impl_opengl3.cpp" PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE) +# the settings (Global, GetGlobalSettings()) are a function-local static read everywhere all the time: MSVC's check of its +# thread-safe initialisation reads the thread's epoch from the TLS on every call. it's made once, by the main thread, before +# any other thread starts, so the plain check of the static does; the only function-local static of the file. without the +# precompiled header, which is built with the default +if(MSVC) + set_source_files_properties("utilities/Globals.cpp" PROPERTIES COMPILE_OPTIONS "/Zc:threadSafeInit-" SKIP_PRECOMPILE_HEADERS TRUE) +endif() if (WITH_CRASHPAD) set(DEFINITIONS ${DEFINITIONS} "WITH_CRASHPAD")