Are foreground applications allocated more system resources than others?

Sometimes it seems like Time Machine backups, file transfers, and software updates speed up after focusing their windows.

Is this just psychological or an actual feature?


Solution 1:

It's most probably not psychological as multiple things affect the allocation of system resources, and being a foreground window is one of them.

In general all processes (and even threads) running on a system has a priority, which is used to determine the amount of CPU resources made available to it. If you open a normal GUI program, it will start with a priority of 46. If it is the foreground window, the priority is increased by 1 to 47.

The actual range of priorities on a live system is much larger as other things factor into the process priority. They range from 0 (lowest priority) to usually 97 (queue in a real time process). For ordinary programs you run, you'll usually see priorities such as 20 (utility program), 31 (base priority), 46 (background) and 47 (foreground).

You might be experiencing the impact of a feature known as "App Nap". It essentially slows down applications that the system thinks the user is not actively using in order to speed save energy and/or improve performance of other apps.

Specially it targets apps that are:

  • not the foreground (selected) app
  • hasn't recently updated visible information on screen
  • isn't playing audio
  • isn't using OpenGL 3D graphics
  • isn't actively managing energy usage using IOKit/NSProcessInfo

When those conditions are in place, the application can be put into App Nap. If you look at Activity Monitor in the Energy tab, you'll see a column named "App Nap". If this says "Yes", the app is napping.

When an application is in App Nap it runs slower due to a reduction of its CPU priority, throttling of I/O and throtting of timers.

You can read more about App Nap in Apple's documentation here:

https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/AppNap.html

As far as I recall, the priority of an App Nap'ed program is 4.