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

Increased performance on 16+ core CPUs by limiting VRAD. #106

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Lpfreaky90
Copy link
Contributor

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

Updated personal branch to be up-to-date with main branch
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
@Exactol
Copy link
Collaborator

Exactol commented Mar 17, 2020

How will this affect modded compile tools that support up to 32 threads? https://developer.valvesoftware.com/wiki/Increased_Thread_Limit_for_Compile_Tools

@Lpfreaky90
Copy link
Contributor Author

Good question, I'm not sure, will investigate.

@Lpfreaky90
Copy link
Contributor Author

Lpfreaky90 commented Mar 17, 2020

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.

@Exactol
Copy link
Collaborator

Exactol commented Mar 17, 2020

Trying to detect how many threads its using does seem kindof hacky. I think adding a flag would be the best option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants