Skip to content

Performance issues with swiCleanup #40

@jeffposnick

Description

@jeffposnick

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]:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions