M BUZZ CRAZE NEWS
// updates

Any benefit to setting CPU affinity for a game?

By Daniel Rodriguez

Would there be any possible benefit in setting the CPU affinity for a game? Like Starcraft 2, for example.

I've heard suggestions to do this, such as choosing real cores only (no hyperthreaded cores), choosing cores of a certain number, choosing "matching" cores, etc., and that there's benefit to be had in doing this.

But like many tips and tweaks on the interwebz, I'm wondering if this is just some digi-voodoo, or if there are actual benefits to be had (performance, stability, stutters) -- even if just potential.

2

3 Answers

It depends on the game and the OS. Many games are not written with multi-core support in mind, but still make use of OS-level primitives that cause the OS to migrate processes between cores, which in some cases can impact performance due to cache line misses and resource allocation issues, and depending on the graphics hardware this can theoretically make a big difference, although the difference will be greater on systems with multiple distinct CPU chips rather than multi-core CPUs that share a cache and so on. Some games might even break without CPU affinity set, because they were only tested on single-core systems and make some bad assumptions about the order of operations that occur in asynchronous APIs.

The best thing to do is to try it and measure the difference, if any, and re-measure it every time there's a new graphics driver or API version update, since future versions of graphics drivers in particular can change things immensely.

That said, if a game is written to take advantage of multiple cores, then it never makes sense to set the CPU affinity on it.

1

Day9 claimed back in 2010 that it has some effect. In some other casts he said that he invested a lot of time into tweaking his setup, because he did not have a lot of money, his computer kept overheating and everybody wanted him to stream in HD.

Some time ago he gave a Video Streaming Tutorial

His setup is as follows

  • Encoder CPU: 0,1,2,3
  • Starcraft 2 CPU: 4,5
  • Screen Capturing Software CPU: 6,7

As long as the CPUs are going to be used all the time it makes sense that the same programs should keep using them to save context switches.

Then again it was back in 2010 and maybe the operating systems do a better job of this.

I would give it a try to see if the results are better, but only if you need your computer to do a lot of computation at the same time.

If you just play Starcraft, without streaming, it is easier to disable, close or suspend any other applications or services that might drain a lot of resources.

This, at best, is a micro optimization and if you see any measurable performance improvements in game, you'll likely affect other aspects of your system. Remember that while you are running the game, windows services and other processes are still working.

So, rather than attempting to do something like setting the processor affinity, you'd be better off closing as many other applications as possible to keep the CPU (and memory) as free as possible.

I'd expect you'll see greater gains here (although still minor) with much less work.