Skip to content

parsePage is quadratic on deeply nested anchors (45 s at 20,000) #1844

Closed

Description

@nc9

Found while speeding up the test suite (#1839, pub#1843). parsePage takes time quadratic in nesting depth when a page has deeply nested anchors: about 45 s at 20,000 nested anchors, while the rules over the same parsed page took 0.4 s (measured in packages/rules/tests/integrity-budget-784-nested.test.ts before pub#1843 shrank that fixture to 2,500). The rule-side visit budget (#784, 400,000 visits per page) bounds the rules, not the parse, so a hostile page with deep nesting can hold an audit in the parser for tens of seconds.

Acceptance Criteria

  • A benchmark or test shows parsePage time on N nested anchors for N = 2,500, 5,000, 10,000, 20,000, before and after, and the after curve is roughly linear (20,000 under 2 s on a dev machine, stated with the machine).
  • The cause is named in the PR (which step is quadratic: the DOM build, a per-node ancestor walk, link extraction, or another pass).
  • Parse output for normal pages is unchanged (existing parser and golden tests pass with no snapshot change).
  • Parse time on hostile nesting is bounded: either the parse is linear in input size, or a parse budget (nesting depth or work units) stops it, documented, and the page reports the truncation instead of silently dropping content.
  • A regression test packages/parser/tests/nested-anchors-parse-time-1844.test.ts parses 20,000 nested anchors and fails if it takes over a stated bound (with headroom for CI), and checks the parsed link count (or the reported truncation) so a fix cannot pass by returning nothing.

Activity

  1. added
    size: M
    performance
    on Nov 14, 2026
  2. added theissue type on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancesize: M

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions