From bcf3d177d3476a1696b034544f5cfcf68404663b Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Sun, 15 Nov 2026 10:17:24 +0000 Subject: [PATCH] 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 --- packages/lint/src/project.test.ts | 11 +++++++---- packages/lint/src/rules/composition.ts | 8 +++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/lint/src/project.test.ts b/packages/lint/src/project.test.ts index 7b45a7f219..ed36fa5586 100644 --- a/packages/lint/src/project.test.ts +++ b/packages/lint/src/project.test.ts @@ -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 = ''; const project = makeProject(validHtml().replace("", `${links}`)); @@ -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", () => { diff --git a/packages/lint/src/rules/composition.ts b/packages/lint/src/rules/composition.ts index 96118e1d83..cffb014d33 100644 --- a/packages/lint/src/rules/composition.ts +++ b/packages/lint/src/rules/composition.ts @@ -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;