perf(lint): scan CSS url references in linear time (#7829)

* perf(lint): scan CSS url references in linear time; the test checks growth, not wall time

* test(lint): cap one large malformed stylesheet instead of comparing two small timings
This commit is contained in:
Michael Wang
2026-11-15 10:17:24 +00:00
committed by GitHub
parent eaf33bc658
commit bcf3d177d3
2 changed files with 10 additions and 9 deletions
+7 -4
View File
@@ -549,7 +549,10 @@ describe("texture_mask_asset_not_found declarations", () => {
},
);
it("reads long runs of unclosed urls in valid and malformed stylesheets in well under two seconds", async () => {
it("reads long runs of unclosed urls in valid and malformed stylesheets in linear time", async () => {
// A linear scan lints these stylesheets in about 0.1 s on a laptop. A quadratic one takes
// over 10 s, because it reads to the end of broken.css after each unclosed url(. The cap
// leaves room for slow shared CI runners.
const links =
'<link rel="stylesheet" href="nested.css"><link rel="stylesheet" href="broken.css">';
const project = makeProject(validHtml().replace("<body>", `<head>${links}</head><body>`));
@@ -557,13 +560,13 @@ describe("texture_mask_asset_not_found declarations", () => {
join(project, "nested.css"),
`a{background:${"url(".repeat(40_000)}${")".repeat(40_000)}}`,
);
writeFileSync(join(project, "broken.css"), `a{${"mask-image:url(".repeat(3_000)}`);
writeFileSync(join(project, "broken.css"), `a{${"mask-image:url(".repeat(30_000)}`);
const started = performance.now();
await lintProject(project);
expect(performance.now() - started).toBeLessThan(2000);
});
expect(performance.now() - started).toBeLessThan(4000);
}, 60_000);
});
describe("template shell style sources", () => {
+3 -5
View File
@@ -22,6 +22,7 @@ import {
isSafeMediaUrl,
} from "@hyperframes/parsers/composition";
import { COMPOSITION_ATTRIBUTES, readClipTiming } from "@hyperframes/parsers/composition-contract";
import { rawCssUrlMatches } from "@hyperframes/parsers/css-url-scans";
import { resolveCompositionDuration } from "@hyperframes/parsers/composition-duration";
import {
readAuthoredDurationSeconds,
@@ -132,11 +133,8 @@ function isCompositionRootOrMount(rawTag: string): boolean {
// rules that consume this — the helper just yields raw URL values.
function extractCssUrlReferences(css: string): string[] {
const out: string[] = [];
const noComments = replaceBlockComments(css, "");
const urlPattern = /\burl\(\s*(["']?)([^)"']+)\1\s*\)/g;
let m: RegExpExecArray | null;
while ((m = urlPattern.exec(noComments)) !== null) {
const raw = (m[2] ?? "").trim();
for (const { parts } of rawCssUrlMatches(replaceBlockComments(css, ""))) {
const raw = (parts[2] ?? "").trim();
if (raw) out.push(raw);
}
return out;