web-vitals-extension icon indicating copy to clipboard operation
web-vitals-extension copied to clipboard

Prevent the cache from growing uncontrollably

Open rviscomi opened this issue 3 years ago • 2 comments

Click on the extension icon to open the popup window and enter DevTools for that window. In the console type chrome.storage.local.get(console.log) and you should see entries for every tab you've visited while the extension was installed. (mine is over 5k entries)

We should flush the cache once in a while to avoid this from building up. Open questions: How often? What should trigger it? What shouldn't get flushed?

One idea is to implement this something like a LRU cache, maintaining a maximum number of items in the cache at any given time, and evicting the oldest item when it's full and something new needs to be added.

rviscomi avatar Dec 24 '20 01:12 rviscomi

Hi @rviscomi 👋

I've stumbled upon the web-vitals project just over a month ago when I was about to launch a personal website and wanted to check the performance (I was interested in first contentful paint amongst others). I found the extension super useful and wanted to contribute back to the project 🙂 .

I wanted to check with you if this issue has passed the necessary (internal) triage and is up for grabs to first time contributors to the project? 🙂

Looking at the code, it seems to me that the necessary logic should be added here, just before pushing new entries to the cache. It would be great if you could please provide more info on the the issue, as for example a threshold for the LRU cache (if one was to take that approach) in order to successfully implement this 🙂 .

Many thanks! 🎉

ognjenjevremovic avatar Mar 03 '21 11:03 ognjenjevremovic

Hi @ognjenjevremovic sorry I missed your message (I was on leave at the time) but just seeing it now. Would you still be interested to contribute to the extension?

rviscomi avatar May 11 '22 20:05 rviscomi

It won't grow uncontrollably but will grow up to a max of 5MB (which is still quite a lot!): https://developer.chrome.com/docs/extensions/reference/storage/#storage-areas FYI you can use chrome.storage.local.getBytesInUse(console.log); to get the current size.

However, I don't think any of this stuff needs to be stored in local storage. I think session storage should be enough. Testing it out it seems to work, and gets cleared out on restart. The downside is that it means you don't get the original CWVs when restarting the browser, but I think that's OK? Also it has a higher limit (10MB) so it might actually be worse for really long lived sessions.

TLDR I don't think it's a big issue, but maybe we move to session storage. WDYT?

tunetheweb avatar Jul 17 '23 18:07 tunetheweb