Skip to content

perf(tech-detect): tag-attr detectors read one parsed list of tags instead of rescanning per signature #1456 - #1467

Closed
nc9 wants to merge 2 commits into
mainfrom
fix/tech-tag-attr-1456
Closed

nc9 wants to merge 2 commits into
mainfrom
fix/tech-tag-attr-1456

Conversation

@nc9

@nc9 nc9 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1456. Coordinates with #1464 (Klaviyo): no shared lines, this PR touches the Clerk lines of other.ts, not the Klaviyo block.

Cause and change

Signatures that matched a script src, a stylesheet link or a data-* flag were regexes starting at <script\s, <link\b, ... with a bounded [^>]{0,300..400} look-ahead. Bounded per pattern, but a page of unclosed openers pays it after every opener for about a hundred signatures: 5 MB of <script took 20 to 30 s.

  • New detector type tag-attr (tags, attrs, pattern, optional tokens for srcset-style lists). The page pass that already builds pageMarkup now also keeps the attributes of script, link, img, source, iframe, video, audio, embed, object and input tags (quote-aware, linear, comments excluded; 100,000 tags and 100 attributes per tag at most), and a tag-attr detector reads that list. COLLECTED_TAGS is shared; a detector on a tag the pass does not keep throws where it is built.
  • scriptSrc() and resourceAttr() build tag-attr detectors, so every signature that used them moves; facebook-pixel's script src, Clerk's two script attribute flags, RequireJS data-main and the five <link href> CSS-framework patterns in generated.ts (hand edit: the generated file's source data is not in the repo) were converted by hand.

Measured (5 MB pages, whole detectTechnologies, loaded machine)

page main here
<script openers 20 to 27 s 1.1 s
<script x=" 18 s 1.9 s
<link openers 30 s under 1.5 s
<img openers 30 s 0.4 s
plain 1.1 s 0.8 s

Fifteen tag names x (open, quote) were run: none above 1.8 s.

Equivalence

  • 22 real library bundles (inlined and external, with and without bodies): no differences, none added.
  • 16 real homepages (wordpress.org, github, vercel, stripe, bbc, shopify, nextjs.org, react.dev, bootstrap, bulma, cloudflare, mozilla, wikipedia, laravel, hacker news, wordpress.com): identical technology lists.
  • Behaviour changes, listed honestly. Gained: an unquoted, single-quoted or late (past 300 characters) src or href is found; a tag that repeats an attribute uses the first, as browsers do. Gone: matches that were only text, which the old per-signature regex scan accepted: document.write('<script src=...>') in inline JavaScript, a tag written inside a string literal, a link href inside a script string, tag text inside an attribute value, and a commented-out <script src=...>.

Tests

tag-attr-1456.test.ts (15): quoted, single-quoted, unquoted, late and upper-case src; commented-out tag, data-src, anchor and prose negatives; stylesheet link, link-is-not-anchor; Clerk and RequireJS data attributes; Meta Pixel; the unknown-tag guard; 5 MB hostile pages (script, link, img, iframe x unclosed openers and unbalanced quotes, under 6 s). All tech-detect suites pass; tsgo clean.

Docs: none (internal). CHANGELOG bullet. Skill change: none. The corpus check (53) is for after release.

nik

Review round

  • Memory: each collected tag kept every attribute (8 MB of 100-attribute <img>: 50 MB became 499 MB, 255 MB retained). Now only the attribute names some tag-attr detector reads are kept (derived from the signature list in use, per call), tags with none are not kept, the walk over a tag's attributes is bounded, and the parsed tags and markup are dropped when the call returns.
  • Bounds tests: <img a=" + newline and <script a=' + newline openers at 5 MB, a 1 MB attribute value on img and on script src, and a heap check after 8 MB of 100-attribute tags (under 60 MB retained). Closes the bounds criterion of tech-detect: in-tag script, link and img patterns are quadratic on line-start openers inside a quoted attribute #1474.
  • Rebased on main v0.0.153 (CHANGELOG only).

nc9 added 2 commits November 1, 2026 12:47
…e's tags instead of rescanning the HTML per signature #1456

Signed-off-by: Nik Cubrilovic <[email protected]>
…he parsed tags per call, bounds tests; honest behaviour list #1456

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/tech-tag-attr-1456 branch from 156d276 to 4e24099 Compare November 1, 2026 02:02
@nc9 nc9 mentioned this pull request Nov 1, 2026
@nc9

nc9 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Landed in v0.0.154 as 8c8528a9 9cc866bf via #1493. Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.154. Closing this original.

nik

@nc9 nc9 closed this Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tech-detect: a 5 MB page of unclosed <script openers takes about 12 s because every script-src signature rescans it

1 participant