Skip to content

check: text_occluded hit-tests 27 points per text element, so the layout audit grows with the square of on-screen text (577 blocks: 1.2 s per sample) #9213

Backlog

Description

@miguel-heygen

What happens

The layout audit (window.__hyperframesLayoutAudit, packages/cli/src/commands/layout-audit.browser.js:3032) runs occludedTextIssue (layout-audit.browser.js:1942) for every visible text element at every layout sample. occlusionCoverage (layout-audit.browser.js:1712) probes a 3 x 9 grid per text fragment, and every probe calls occluderAt (layout-audit.browser.js:1666), which calls document.elementsFromPoint(x, y).

So each audit call does 27 hit tests per text element (more for multi-line text), and the cost of one hit test itself grows with the number of elements on screen. The result is quadratic in on-screen text. On a plain layout almost every probe ends at the first stack entry, because the topmost element is the text itself or its ancestor (isForeignElement is false and occluderAt returns null), so nearly all of that hit-testing finds nothing.

Measured

Linux x86_64, Node 22.23.4, the check's own headless Chrome (158, software GL), main at f298d23 with #9201 applied on top (ecdd111). Shared machine; times move by about 20% between runs, the ratios held.

Fixture: 10 scenes of 6.2 s, each with a grid of absolutely positioned word spans that do not touch, so nothing is occluded and check reports no findings. Words per scene doubled twice. Page CPU profile of a full check --no-cache (9 layout audit calls per run):

Text blocks on screen Layout audit total elementsFromPoint Per audit call
145 0.84 s 0.71 s 93 ms
289 2.94 s 2.67 s 327 ms
577 10.89 s 10.26 s 1.21 s

Growth per doubling: 3.5x, then 3.7x. Per hit test: about 20 microseconds at 145 blocks and 73 at 577. With the default 9 samples this is 11 s at 577 blocks; --samples, --at and --at-transitions multiply it.

The fixture generator is the same one attached to the companion issue about seek cost; this table used SCENES=10 PREFIX=w with ROWS=12 COLS=12, ROWS=12 COLS=24 and ROWS=24 COLS=24.

Suggested fix

Skip hit tests that cannot find a foreign element. Once per audit call, collect the bounding rects of the rendered elements (the audit already walks them for visibleElementsIn and restoreHitTesting), and put them in a simple grid index (for example 64 px cells). Before calling elementsFromPoint for a probe point, check whether any element that is neither the text element, nor its ancestor, nor its descendant has a rect containing the point. If none does, the hit test can only return the text and its relatives, so occluderAt would return null; skip it.

A rect is a superset of what can be hit (transforms are already in getBoundingClientRect, and clip-path only shrinks the hit area), so the findings should not change. Two cases to check by hand: elements inside shadow roots (the host's rect can be smaller than what its shadow content paints) and elements outside the composition root (overlays on body), which the index must include. If either is hard to bound, fall back to the hit test for that text element.

The findings order does not change, since the outer loop over elements stays the same.

How to verify

  • Tests: extend packages/cli/src/commands/layout-audit.chromium.test.ts (real hit testing) with: text under an opaque sibling, text under an element that only covers it through a transform, text under a body-level overlay, text inside and under a shadow-root host, and a page of many non-touching labels. Assert the same text_occluded findings and coveredFraction values as today.
  • Equivalence: on a set of generated layouts, run the audit with and without the pre-filter in the same page and compare the returned issues with JSON.stringify.
  • Scale benchmark: regenerate the three fixtures above and time window.__hyperframesLayoutAudit({ time }) in the page (or read the layout audit share of a page CPU profile of check). The per-call time should grow close to linearly with on-screen text, and elementsFromPoint should drop to a small share.

Activity

  1. added
    difficulty/medium
    enhancement
    help wanted
    triage/ready
    on Dec 1, 2026
  2. ManasDasri commented on Dec 2, 2026

    @ManasDasri

    Hi, I'd like to pick this up.

    Plan is the pre-filter from the issue: once per audit call, bucket the rects of every element in the document into a 64px grid, and have occluderAt skip elementsFromPoint when no element unrelated to the text has a rect over the probe point. Putting it in occluderAt also covers the isBuried path in canvasCoveredIssue.

    For the cases where the border box isn't a safe bound on what can be hit (shadow hosts, ::before/::after, text overflowing its box) I'll widen the rect or treat the element as covering everything, so those pages just fall back to the full hit test.

    I saw #9256 takes the top-hit shortcut and leaves the scaling part open. The two should stack fine. Tests will be the cases listed under "How to verify", plus an equivalence check with and without the index on generated layouts.

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

    area/tooldifficulty/mediumenhancementhelp wantedtriage/ready

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions