From fa46a2c336c6da8b16ca7cab0e8e4c11d32b8ecf Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 13 Apr 2017 21:03:25 +0300 Subject: [PATCH] split filterStyles() js engines don't like big functions (V8 often deoptimized the original filterStyles), it also makes sense to extract the less frequently executed code --- storage.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/storage.js b/storage.js index 454f0e6a..4fc861cc 100644 --- a/storage.js +++ b/storage.js @@ -110,12 +110,36 @@ function filterStyles({ if (cached) { cached.hits++; cached.lastHit = Date.now(); - return asHash ? Object.assign({disableAll}, cached.styles) : cached.styles; } + return filterStylesInternal({ + enabled, + url, + id, + matchUrl, + asHash, + strictRegexp, + disableAll, + cacheKey, + }); +} + + +function filterStylesInternal({ + // js engines don't like big functions (V8 often deoptimized the original filterStyles) + // it also makes sense to extract the less frequently executed code + enabled, + url, + id, + matchUrl, + asHash, + strictRegexp, + disableAll, + cacheKey, +}) { if (matchUrl && !cachedStyles.urlDomains.has(matchUrl)) { cachedStyles.urlDomains.set(matchUrl, getDomains(matchUrl)); for (let i = cachedStyles.urlDomains.size - 100; i > 0; i--) { @@ -133,6 +157,7 @@ function filterStyles({ // of edit.html with a non-existent style id parameter return filtered; } + const needSections = asHash || matchUrl !== null; for (let i = 0, style; (style = styles[i]); i++) { @@ -150,6 +175,7 @@ function filterStyles({ } } } + cachedStyles.filters.set(cacheKey, { styles: filtered, lastHit: Date.now(), @@ -158,6 +184,7 @@ function filterStyles({ if (cachedStyles.filters.size > 10000) { cleanupCachedFilters(); } + return asHash ? Object.assign({disableAll}, filtered) : filtered;