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.34k stars 105 forks source link

Initialise locale formatting in advance as a performance improvement #179

Closed tunetheweb closed 3 months ago

tunetheweb commented 3 months ago

Issue raised in https://github.com/GoogleChrome/web-vitals-extension/pull/178#discussion_r1593065236

This initialised the formatters once as the extension is initialised, rather than with each metric update for a god performance improvement, but also allows us to keep the INTL option.

tunetheweb commented 3 months ago

@brendankenny upon suggestion from @rviscomi I'm initialising the three formatters needed up front once, rather than each time the metric changes.

As the extension is only initialised after the document is complete there's a bigger chance it's idle then (not guaranteed, but best chance) so initialising the NumberFormat then (and only then) is best place to init it.

WDYT?