From e5bea21923180d48f1105b5c4dd58f6d48228ecd Mon Sep 17 00:00:00 2001 From: krzychu124 Date: Tue, 23 May 2023 17:29:03 +0200 Subject: [PATCH] Reduce max number of threads for high core/thread count CPUs (20c/t+) --- TLM/TLM/Custom/PathFinding/CustomPathManager.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/TLM/TLM/Custom/PathFinding/CustomPathManager.cs b/TLM/TLM/Custom/PathFinding/CustomPathManager.cs index 4ced2f1f8..f6945b401 100644 --- a/TLM/TLM/Custom/PathFinding/CustomPathManager.cs +++ b/TLM/TLM/Custom/PathFinding/CustomPathManager.cs @@ -146,12 +146,14 @@ public void UpdateWithPathManagerValues(PathManager stockPathManager) { PathFind[] stockPathFinds = GetComponents(); int numOfStockPathFinds = stockPathFinds.Length; // utilize more threads if possible (systems with 8+) otherwise use vanilla calculation - int numCustomPathFinds = SystemInfo.processorCount < 8 - ? Mathf.Max(SystemInfo.processorCount / 2, 1) - : SystemInfo.processorCount - 4; + // <=8t CPU -> 1..4 PT threads (vanilla) + // 10t CPU -> 5 PT threads + // 16t CPU -> 8 PT threads (2x vanilla) + // >=20t CPU -> 10 PT threads + int numCustomPathFinds = Mathf.Clamp(SystemInfo.processorCount / 2, 1, 10); simSleepMultiplier_ = CalculateBestSimSleepMultiplier(numCustomPathFinds); - Log._Debug("Creating " + numCustomPathFinds + " custom PathFind objects. Number of stock Pathfinds " +numOfStockPathFinds); + Log._Debug($"Detected {SystemInfo.processorCount} CPU thread(s). Creating {numCustomPathFinds} custom PathFind objects. Number of stock Pathfinds {numOfStockPathFinds}"); _replacementPathFinds = new CustomPathFind[numCustomPathFinds]; FieldInfo f_pathfinds = typeof(PathManager).GetField( "m_pathfinds",