appfap - AppNap for Linux prototype

An AppNap prototype for Linux, made by my colleague Rugginoso. This is just the basic idea for now: using cgroups to reduce CPU scheduling time for background windows. This is much better than changing niceness / io-niceness, and sounds closer to what Mac OSX does.

It looks like that finding “background” windows is not that easy:

You need to talk to the window manager to see if the window is visible, taking into account the current desktop, any occluding window including their transparency map, and any semi-transparent windows (eg: many people have semi-transparent terminals). Probably the best way would be to patch windows managers (or Wayland?) to expose this information, and then hook it up

You need to talk to pulse audio to have a list of apps that are emitting audio, including any volume control (so that you separate apps that are really audible by the computer users from those connected to PulseAudio but not emitting any sound at the moment, or muted by the user), and any networking audio destination (PulseAudio can tunnel audio via TCP).

Then, it would be useful to hook up into Chromium some way, to detect visible tabs (and their processes) and invisible tabs (to be throttled down). Not sure what’s the best way, probably just exposing some APIs from AppFap and then calling them from within Chromium.

Our colleague DVD also suggested a further improvement: if the laptop is running on battery, the cgroup setting is the correct one, but when the laptop is on power, it might still be interesting to change niceness and io-niceness of background processes to increases responsiveness of foreground applications. Programmers know how to run “nice make -j4”, but users might get frustrated by a background video encoding slowing down web browsing, so even if you’re not trying to save battery, it might still be good for the desktop user experience.