Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize max number of Pathfinding threads for high core/thread count CPUs #1744

Merged
merged 1 commit into from
May 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions TLM/TLM/Custom/PathFinding/CustomPathManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,14 @@ public void UpdateWithPathManagerValues(PathManager stockPathManager) {
PathFind[] stockPathFinds = GetComponents<PathFind>();
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",
Expand Down