-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Following up on some traces that @wanderview performed on navigation requests to https://chromeos.dev/, it looks like there's a synchronous JS microtask delay of ~1.5s (on desktop Chrome), with much of it attributable to the swiCleanup callback function's usage of [Symbol.split]:
static-site-scaffold-modules/modules/service-worker-includes/index.js
Lines 84 to 115 in e1cd1cd
| async function swiCleanup({ response }) { | |
| const content = await response.text(); | |
| const matches = content.match(includesRegExp); | |
| // const neededIncludes = [...new Set(matches)].map(i => i.split(includesFileRegExp)[1]); | |
| let open = 0; | |
| const rebuild = content | |
| .split(includesRegExp) | |
| .map(i => { | |
| // If the current item is the include and it's not included from within | |
| if (matches && i === matches[0]) { | |
| matches.shift(); | |
| open++; | |
| if (open > 1) return ''; | |
| return i; | |
| } | |
| const endIncludeSplit = i.split(endIncludeWithLeadingRegExp); | |
| if (endIncludeSplit.length === 1 && open !== 0) { | |
| return ''; | |
| } | |
| const count = i.match(endIncludeRegExp); | |
| open = open - (count ? count.length : 0); | |
| return endIncludeSplit.join(''); | |
| }) | |
| .join(''); | |
| return new Response(rebuild, { headers: response.headers }); | |
| } |
This might be due to the complexity of the RegExps being passed to .split(), the size of the source string that the RegExps are being run against, or something else regarding the algorithm in that function.
If it turns out to be correlated to the complexity of the RegExps, it might be worth checking whether the related serviceWorkerInclude function could be sped up in a similar way, since that's using a similar set of RegExps.