Skip to content

perf(cli): skip occlusion hit tests where nothing could cover the text - #9285

Open
ManasDasri wants to merge 1 commit into
heygen-com:mainfrom
ManasDasri:perf/occlusion-hit-index
Open

ManasDasri wants to merge 1 commit into
heygen-com:mainfrom
ManasDasri:perf/occlusion-hit-index

Conversation

@ManasDasri

Copy link
Copy Markdown

What

The layout audit now skips the elementsFromPoint call for an occlusion probe when nothing on the page could cover the text at that point.

Why

Every visible text element gets 27+ hit tests per audit call, and each hit test costs more as the page fills up, so check slows down with the square of on-screen text. On a plain layout almost all of those hit tests find nothing.

Related work

Fixes #9213. #9256 swaps in a top-hit shortcut inside occluderAt. That helps where this doesn't: text over an opaque full-frame backdrop that sits behind it, where every probe still has a candidate under it. The two should stack.

How

At the start of each audit call, the elements that isOpaqueOccluder could accept (img/video/canvas, or an opaque background) go into a 64px grid by their bounding rect. occluderAt checks the grid first. If no element unrelated to the text covers the probe point, it returns null without a hit test. Elements that can't cover anything don't need to be in the grid, because a hit on them only makes the walk continue.

A bounding rect is a safe outer limit for most hit areas. Transforms are already in it and clip-path only shrinks things. These cases can reach outside their own rect, so the grid treats them as covering the whole page and those probes still get a real hit test:

  • shadow hosts and custom elements
  • ::before/::after
  • list items (markers)
  • SVG children: bounded by the outer <svg>, unbounded when it's overflow: visible

Text nodes widen their parent's rect in case the text overflows the box.

Elements on body outside the composition root are indexed too. isBuried in canvasCoveredIssue goes through occluderAt, so it gets the same skip.

Test plan

  • New Chromium cases: text under an opaque sibling, under a sibling moved over it by a transform, under a body overlay, under a shadow host whose shadow content reaches past its box, under an ::after box painted past its owner, text slotted inside a shadow host, and a 144-label page that should run zero hit tests. The expected coveredFraction values came from running these tests against main's script, where everything passes except the zero-hit-test case. With the shadow and pseudo-element guards removed, those two cases fail.
  • Equivalence: 400 random layouts (opaque/translucent boxes, rotations, SVG strokes, ::after boxes, shadow hosts, clip-path, lists, fixed overlays). Audit output compared with JSON.stringify against main: 2726 text_occluded findings, no differences. Without the shadow/pseudo guards, 27 of 100 layouts differ.
  • bunx vitest run src/commands/layout-audit: 409 passing.
  • Comment citation and ratchet checks pass.

Per-call window.__hyperframesLayoutAudit time, median of 5, labels on a 1920x1080 stage (Apple M4, Brave 158 as the Chromium):

Labels main this PR hit tests per call (main → PR)
144 121 ms 20 ms 3888 → 0
288 467 ms 56 ms 7776 → 0
576 1824 ms 189 ms 15552 → 0

With an opaque full-frame sibling behind the labels, the times stay the same as main, as described above. What's left of the growth comes from the other detectors, not from hit testing.

Each layout audit now indexes the elements that could occlude text (raster
tags and opaque backgrounds) into a 64px grid. occluderAt skips
elementsFromPoint for a probe when no element unrelated to the text could
be hit there. Elements whose hit area can reach past their box (shadow
hosts, custom elements, ::before/::after, list items, SVG under an
overflow:visible root) count as covering the whole page for the text they
are foreign to, so those cases fall back to the full hit test.

Refs heygen-com#9213

This branch has not been deployed

No deployments
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.

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)

1 participant