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

Freezes firefox on startup when using 'Prepend a symbol' feature witha large number of tabs #362

Open pallaswept opened 8 months ago

pallaswept commented 8 months ago

I've been using another addon to suspend my tabs for some time, and it works well, but it's UX was a little cumbersome - I had to open the add-on's UI, change tabs, and press a button, to manually trigger suspension of all tabs. I went to look for an alternative, and this one is by far the most popular on AMO, and is a "recommended" addon (Congrats on both counts!) and had a much easier way to manually trigger the suspension, so I installed it and gave it a try.

At first, it seemed to work perfectly well, I disabled the other addon, and switched to this one instead, I found it to be equally (perhaps more) featured, but also it had a better UX. I was very happy. I used it for at least an entire day before I had any trouble, and had restarted Firefox several times during that period.

Then I restarted my PC today, after closing a fully-working Firefox session, and when I started Firefox, it froze up. Presuming I had some kind of corruption, I restored from a backup earlier in the day (I use BTRFS so I had hourly snapshots), started up this restored session which had been working fine when I used it, and Firefox still froze up at startup. I then restored from a backup from the previous day, a past Firefox session, which had worked, shut down, and started up again with no problem, so that one had to be OK....annnnd nope, still froze. I went through my profile trying to think of things I might have changed, disabled this addon and CookieAutoDelete, since I'd changed both of their configurations in that past 24 hours)... and it STILL froze up at start.

In the end, I started in private mode, so I could entirely disable this addon and CAD, then started a normal session, and it was still freezing up - but realised that while the browser was largely unresponsive, it would in fact respond to mouse clicks, maybe after several minutes passed for each click, so I waited patently for about 30 minutes until the browser became sufficiently responsive that I could reload all of the tabs, so as to bring them out of their suspended state. I then restarted FF, and boom, fixed. I enabled CAD again, restarted, still good. Enabled this addon, restarted, and....frozen again.

At this point, I had 10 browser windows open, with 50-100 tabs in each. So, that amounted to a LOT of suspended tabs. Total suspender is currently reporting 448 suspended tabs, so it would have been in that neighbourhood, likely more. Quite possibly >500 (thinking round numbers) or >512 (thinking about binary number limitations). It seems that there's some kind of limit to the number of suspended tabs which this addon can handle, and beyond that, it freezes up, and freezes the whole browser along with it.

Another theory I have, as to why it seemed to work, is that in previous restarts, I had 9 windows open, but when it failed, I had 10 browser windows open, and this add-on set to suspend tabs when there are 10 tabs open (after 30 minutes). So maybe it was that it was suspending instantly and started sooner than expected?

I also had changed the setup to change the icon, to the 'power' icon given in the UI, so perhaps it was something to do with it changing the titles? I'm not sure.

Whatever it was, I suspended all the same tabs, using that other add-on, and Firefox restarts perfectly happily. If I suspended them with this addon, Firefox would freeze up on startup.

I tried increasing the maximum number of tabs to discard to 1000 (so it was >500 & >512 as mentioned earlier), and disabled changing the tab favicon.....and after that, triggering the tab discard just did nothing at all. After that, I reduced the maximum from 1000 to 100 (ie, increasing it from 500 to 1000 didn't work, it broke it, so let's try going the other way)...and it still did nothing at all.

Sorry I can't give more info here. I can't really test it because as soon as I enable it, my browser freezes. I did start Firefox from the terminal, so I could see if any errors were returned, but none were. If you have any suggestion as to how I might help, please let me know.... but my experience with is addon has either been that it fails to function whatsoever, or it completely breaks my browser.

pallaswept commented 7 months ago

By a process of elimination I have narrowed this down to an issue with the "Prepend a symbol to the discarded tabs (e.g. 💤 or ⏻︎) (if possible)" Feature. Reproduction steps follow:

It may be relevant that I have Firefox configured to load ALL tabs at startup (browser.sessionstore.restore_on_demand=false) - I have a powerful machine that can handle it just fine, and I don't want to wait around every time I click on a tab from the saved previous session which has not been loaded. I have not altered the setting to load them 'lazily' (browser.sessionstore.restore_tabs_lazily=true as per default), so if the session contains 1000 tabs across 5 windows, I am not loading 1000 tabs simultaneously, but all 1000 tabs will eventually be loaded when I start.

I did not always have this issue, I did not see this issue occur until I had 10 browser windows and over 500 tabs, so a session with at least 10 windows and at least 600 tabs should be used for this process.

Steps to recover and work around this bug:

Steps to confirm that this feature is the cause:

So obviously, there's some kind of problem with loading tabs from a saved session, which have the modified title. It seems to only occur under certain other circumstances, or a mix of them, those being:

Hope this helps you to narrow down the code that is to blame here. I now have a workaround, so I an enjoy this addon and it's more pleasant UX, but I really do like the 'prepend a symbol' feature, so it would be awesome if we could get it fully working. Please let me know if there is anything I can do to assist.