greatsuspender / thegreatsuspender

A chrome extension for suspending all tabs to free up memory
https://chrome.google.com/webstore/detail/the-great-suspender/klbibkeccnjlkjkiokjodocebajanakg/
GNU General Public License v2.0
5.04k stars 905 forks source link

Ability to suspend tabs that use a lot of CPU #448

Open hzhongmj opened 8 years ago

hzhongmj commented 8 years ago

My chrome constantly uses a lot of CPU when I switch between office and home (mainly Google Doc tabs). I was looking to see if I could write an extension to automatically suspend those tabs, before I ran into this extension. It looks a promising start.

What do you think of adding a feature to auto-suspend tabs using CPU more than a set threshold? I may learn to do this but not sure when I can get around to it (I've never tried to write an extension before), but I figure I'd throw this idea out here to see if anyone beats me to it.

DanAtkinson commented 8 years ago

This can get very complicated and messy quickly.

Because Chrome will often lump multiple tabs together into a single process, what you will find is that there's no way to identify which individual tab in that process is choking the CPU. So you'd have to suspend all tabs in that process rather than the one which is causing the CPU spike. This is undesirable.

The threshold would also need to be checked over a period of time. There's no reason why a momentary high CPU spike is a bad thing if it only lasts a few cycles, so you'd need to constantly poll CPU usage on multiple processes. This is inefficient and is somewhat paradoxical - an extension using high CPU looking for tabs using high CPU.

For reference, the relevant API is chrome.processes which is currently only in the dev channel because it's not ready for prime time yet.

hzhongmj commented 8 years ago

Thanks for the reply. That makes sense. Another possibility is to be able to specify which tabs to suspend by URL prefix/regex. For example, I can just specify that Google Doc tabs to suspend (a blacklist instead of a whitelist). That might be less controversial.

RJVB commented 7 years ago

there's no way to identify which individual tab in that process is choking the CPU. So you'd have to suspend all tabs in that process rather than the one which is causing the CPU spike

Actually this may always be undesirable for you in your work flow, but "MMMV". Other users may find this less of a problem, and maybe the lumped tabs are all related one way or another. After all, if you don't want tabs to consume more than X% CPU unless you're working with them, what does it matter if they cause that CPU load on their own or together with other tabs, as long as non are being worked in?

I think it's an interesting idea, assuming a mechanism can be implemented that keeps track of average CPU load per suspendable tab/tab group without causing too much CPU load itself so your other argument becomes moot. Not that I think that keeping track of average CPU load is that expensive provided you're already waking up periodically to perform house keeping.

Of course the browser could do something similar internally, throttle down all tabs taking more than a given amount of CPU over the last X seconds when they don't have focus.

You could also implement an additional whitelist. Never suspend tabs taking less than X% CPU, so other tabs can be suspended more aggressively.

deanoemcke commented 7 years ago

Seeing as chrome.processes is still in the dev channel of chrome, this idea is not possible currently. There IS a workaround to have a blacklist in the current version of the extension: https://github.com/deanoemcke/thegreatsuspender/issues/145