Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make maxTabs configurable based on available storage quota, instead of using an hardcoded limit. #479

Merged
merged 3 commits into from
Aug 18, 2024

Conversation

berdario
Copy link
Contributor

I recently started to use Tabwrangler, but I soon realised that I exceeded 2700 tabs wrangled... I wanted to check/review old tabs that got wrangled, but I unfortunately realised that they got trimmed away, because of the 1000 tabs limit.

I then tried to increase this limit, but disappointingly realised that the default is also the maximum value accepted by Tabwrangler 😞

I'm using tabwrangler to avoid having to remember about tidying up old tabs before the systems starts to become unresponsive, and avoid worrying about losing old context/state by just getting rid of all old tabs (evicting the oldest ones first makes a lot of sense). Knowing that I wouldn't be able to go back and inspect what has been added to the corral brought the worry back (which is why I kept Tabwrangler paused for the last couple of months).

1000 tabs seems a relatively low amount in 2024, so I decided to look into how much each tab weighs (in my experience, little more than 500 bytes each on average), how much storage quota the browser can make available to us and make the maxTabs setting configurable based on that.

While I was at it, I also added a logging statement for when Tabwrangler is finally forced to trim its corral (so at least this operation is not completely silent, and people might open the console to check what has been lost).

@ssorallen
Copy link
Member

ssorallen commented Jul 25, 2024

Thank you for this!

How does Tab Wrangler recover or prevent going over the storage quota? It would be great to use as much of the storage space as possible, but I want to avoid users ending up with a dead Tab Wrangler because their average AVERAGE_TAB_BYTES_SIZE exceeded 600 and put them in a state where Tab Wrangler can no longer write data.

I intentionally capped max tabs at something much smaller than the max storage space because according to the chrome.storage docs, "Updates that would cause this limit to be exceeded fail immediately and set runtime.lastError when using a callback, or a rejected Promise if using async/await."

@ssorallen ssorallen self-requested a review July 25, 2024 02:42
@berdario
Copy link
Contributor Author

How does Tab Wrangler recover or prevent going over the storage quota?

Good question, I haven't tried to check tabwrangler behaviour after exceeding the quota (I just aimed to stay just below the quota)

Updates that would cause this limit to be exceeded fail immediately and set runtime.lastError when using a callback, or a rejected Promise if using async/await.

This makes me think that upon this condition, Tabwrangler would still be able to persist the list of saved tabs after trimming, and so a simple end-user fix would be to lower the amount of saved tabs (thus triggering a trim). But of course, this relies on the storage error being bubbled up to the UI

(I'll try to verify this assumption, but cannot guarantee when I'll be able to do this)

@berdario
Copy link
Contributor Author

berdario commented Aug 5, 2024

This makes me think that upon this condition, Tabwrangler would still be able to persist the list of saved tabs after trimming, and so a simple end-user fix would be to lower the amount of saved tabs (thus triggering a trim)

Ok so, I confirmed that this is actually how it works.

I modified tabwrangler to not enforce the limit (which on my system is estimated to be about 17000 tabs). I generated an export/import file with a list of saved tabs close to the limit, and then I opened a bunch of 30/50 groups of bookmarks, to let tabwrangler wrangle them.

screenshot1

I checked that the storage used increased gradually, with getBytesInUse() until it finally got quota exceeded

After that, the used bytes was still barely below the quota limit (becaused it failed to write).

This of course means that the wrangled tabs would be lost, but IMO that's ok, because:

  1. I intentionally provided a conservative estimate for the space used by a tab
  2. my PR wouldn't change the default value, it would just allow people to increase it past 1000
  3. when people get to the tab limit nowadays, they also silently lose tabs from tabwrangler (though the difference in that case is that those tabs would be the oldest, instead of the newly wrangled ones)

I also reproduced it while I didn't have the Tabwranglers options page open, and I've still been able to observe the quota exceeded error being logged after opening the console after the fact.

I then decreased the limit to 16001 (not 16000 unlike my comment in the console)

screenshot2

and confirmed that, upon the next wrangle attempt, it trimmed away all the extra 2000 tabs, and the newly wrangled tabs are successfully saved.

@ssorallen
Copy link
Member

@berdario Thank you for the investigation. I will review again and get this merged.

@ssorallen
Copy link
Member

Thanks again for all this work. The code is straightforward, you added the test, and the comments are useful. Merging!

@ssorallen ssorallen merged commit 0eac6e5 into tabwrangler:main Aug 18, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants