Open Lpfreaky90 opened 4 years ago
How will this affect modded compile tools that support up to 32 threads? https://developer.valvesoftware.com/wiki/Increased_Thread_Limit_for_Compile_Tools
Good question, I'm not sure, will investigate.
Unfortunately I cannot properly monitor the number of threads that VRAD actually spawns.
A somewhat hacky solution would be something akin this:
//By assigning affinity to the process significantly speed up compiles on CPUs with more than 16 cores.
if ((Name == "VRAD") &&
Environment.ProcessorCount > 16)
{
//Give the system 100ms to spawn all its threads.
System.Threading.Thread.Sleep(100);
//monitor performance for a second.
PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
var cpuUsage = cpuCounter.NextValue();
System.Threading.Thread.Sleep(1000);
cpuUsage = cpuCounter.NextValue();
//if we haven't had full processor uselisation, we don't have a patched dll.
//94.2 > 16/17, means that we have at least 16/17 cores running at 100%
if (cpuUsage < 94.2f)
{
//Hex 0xffff means core use core 0 through 15.
Process.ProcessorAffinity = (IntPtr)0xffff;
}
}```
But putting this behind an option will probably be a cleaner solution.
Trying to detect how many threads its using does seem kindof hacky. I think adding a flag would be the best option
VRAD can run a maximum of 16 CPU threads. (see wiki: https://developer.valvesoftware.com/wiki/VRAD ) On CPUs with more than 16 cores, the process keeps bouncing between cores, creating a severe slowdown. By setting the Processor affinity to cores 0-15, we improve the performance significantly