From 999333c0a1830c1cf5471ccadb426b4edb0c7005 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Fri, 31 Oct 2025 20:48:20 -0500 Subject: [PATCH] Config: Make ConfigInfo use Common::SpinLock to protect the CachedValue. These locks are nearly always uncontested and this makes Config::Get faster. --- Source/Core/Common/Config/ConfigInfo.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Source/Core/Common/Config/ConfigInfo.h b/Source/Core/Common/Config/ConfigInfo.h index 5c9edb741d..32f5db069f 100644 --- a/Source/Core/Common/Config/ConfigInfo.h +++ b/Source/Core/Common/Config/ConfigInfo.h @@ -4,12 +4,12 @@ #pragma once #include -#include #include #include #include "Common/CommonTypes.h" #include "Common/Config/Enums.h" +#include "Common/Mutex.h" #include "Common/TypeUtils.h" namespace Config @@ -70,14 +70,14 @@ public: CachedValue GetCachedValue() const { - std::shared_lock lk{m_cached_value_mutex}; + std::lock_guard lk{m_cached_value_mutex}; return m_cached_value; } template CachedValue GetCachedValueCasted() const { - std::shared_lock lk{m_cached_value_mutex}; + std::lock_guard lk{m_cached_value_mutex}; return {static_cast(m_cached_value.value), m_cached_value.config_version}; } @@ -94,6 +94,10 @@ private: T m_default_value; mutable CachedValue m_cached_value; - mutable std::shared_mutex m_cached_value_mutex; + + // In testing, this mutex is effectively never contested. + // The lock durations are brief and each `Info` object is mostly relevant to one thread. + // Common::SpinMutex is ~3x faster than std::shared_mutex when uncontested. + mutable Common::SpinMutex m_cached_value_mutex; }; } // namespace Config