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
920 stars 79 forks source link

fix(auto-discard): Exclude non-ready tabs from threshold metric #361

Open ditsuke opened 9 months ago

ditsuke commented 9 months ago

Context

I use Sidebery, an extension much like tree-style tabs that lets me divide my trees into workspaces. Tabs in a workspace are only loaded when I switch to that workspace, which means that these tabs shouldn't be taken into account when Auto Tab Discard decides whether to auto-discard by number of active tabs.

Currently, this is not the observed behavior. Auto Tab Discard counts all tabs, ready or not ready, when deciding whether to auto-discard. This means that if I have 10 tabs in my active workspace with 45 in an inactive workspace, Auto Tab Discard will auto-discard tabs in my active workspace even when the number of active tabs is below the threshold (say 50).

Summary of changes

I've added a filter step to the auto-discard process to exclude non-ready tabs from the count of active tabs.

rNeomy commented 8 months ago

Running a meta check simultaneously for all tabs is an expensive operation. To address the issue, use a condition within the loop instead of generating a meta for all tabs.