GoogleChrome / web-vitals-extension

A Chrome extension to measure essential metrics for a healthy site
https://chrome.google.com/webstore/detail/web-vitals/ahfhijdlegdabablpippeagghigmibma?hl=en
Apache License 2.0
2.35k stars 105 forks source link

Prevent the cache from growing uncontrollably #83

Closed rviscomi closed 1 year ago

rviscomi commented 3 years ago

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.

ognjenjevremovic commented 3 years ago

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! 🎉

rviscomi commented 2 years ago

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?

tunetheweb commented 1 year ago

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?