rNeomy / auto-tab-discard

Use native tab discarding method to automatically reduce memory usage of inactive tabs
https://webextension.org/listing/tab-discard.html
Mozilla Public License 2.0
888 stars 76 forks source link

[Feature Request] Unload tabs by their CPU/RAM usage #290

Open anzz1 opened 2 years ago

anzz1 commented 2 years ago

Loving the addon so far ! Been using it for months now and had zero bugs, it has simply just worked 100% of the time, which is amazing.

I have a feature request though which in my opinion would add to it's value immensely.

As the core goal of this is not necessarily reducing the number of loaded tabs, but rather reducing CPU (and by extension, battery/heat/power) usage, RAM and disk I/O. So what would be great, would be the possibility to unload tabs by their resource usage. This data is available in firefox profiler capabilities but it's rather cumbersome going checking the data by hand through the debugging tools.

The feature could be added as a new condition to be mixed with others, like after X open tabs unload tabs which use >X% CPU and/or >X MB RAM / unload the next highest resource usage tab / after X minutes close tabs using X% cpu or X MB RAM / only close tabs which use >X resources.

Adding a tooltip when hovering over a tab which displays their CPU/RAM usage would be neat too.

For my use case as I've moved the FF profile to ram disk and I have plenty of RAM, I don't really care about disk I/O or RAM usage, but badly coded CPU-heavy scripts on some sites makes browsing a slog (not to mention killing the battery when on a laptop), hence this plugin. But a static site which runs very little to no scripts does not really contribute to the resource usage, unlike some badly behaving sites.

And systems which are more starved of RAM, could start unloading tabs by highest RAM usage instead, when total RAM usage exceeds X MB as a condition, for example.

Anyway, just my two cents for now, and keep up the good work !

CTimmerman commented 2 years ago

I wrote this to kill misbehaving tabs, but recently it's been killing Firefox as a whole: https://gist.github.com/CTimmerman/6d1fc20c3fb61ef0ba3e2d6de2c582ce

That should occur less with ATD, now that i'm using that in both Firefox and Chrome.

rNeomy commented 1 year ago

Nice idea, but as far as I know, browser extensions cannot have access to the CPU usage data of browser tabs. I'll keep this open for suggestions.

anzz1 commented 1 year ago

Well Firefox is open-source, maybe pitching an idea to add such a feature wouldn't be a bad idea ...

Meanwhile though, isn't Firefox design that every tab is its' own process? (I'm not familiar with Firefox internals).
If that is the case, extensions do have filesystem access in the profile folder under their respective extension folders, right? If so, then it would be very trivial to write a companion app which could poll the cpu and memory usage of each firefox process and write that information to a file in the extension folder which the extension would proceed to read. Matching each process to its' tab could be less than trivial though.

kepstin commented 1 year ago

It is kind of interesting that Firefox does keep track of all of the information that would be needed here, you can see it in about:performance, about:processes, and you can even see Firefox's built-in low memory tab discard metrics and prioritization in about:unloads.

Could probably make a case for some of this information to be made available to extensions. I don't see any existing issues open on Bugzilla for this.