Repository navigation
perf(cli): skip occlusion hit tests where nothing could cover the text - #9285
Open
ManasDasri wants to merge 1 commit into
Open
ManasDasri wants to merge 1 commit into
ManasDasri wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The layout audit now skips the
elementsFromPointcall 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
checkslows 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
isOpaqueOccludercould accept (img/video/canvas, or an opaque background) go into a 64px grid by their bounding rect.occluderAtchecks 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-pathonly 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:::before/::after<svg>, unbounded when it'soverflow: visibleText nodes widen their parent's rect in case the text overflows the box.
Elements on
bodyoutside the composition root are indexed too.isBuriedincanvasCoveredIssuegoes throughoccluderAt, so it gets the same skip.Test plan
bodyoverlay, under a shadow host whose shadow content reaches past its box, under an::afterbox painted past its owner, text slotted inside a shadow host, and a 144-label page that should run zero hit tests. The expectedcoveredFractionvalues came from running these tests againstmain's script, where everything passes except the zero-hit-test case. With the shadow and pseudo-element guards removed, those two cases fail.::afterboxes, shadow hosts, clip-path, lists, fixed overlays). Audit output compared withJSON.stringifyagainstmain: 2726text_occludedfindings, no differences. Without the shadow/pseudo guards, 27 of 100 layouts differ.bunx vitest run src/commands/layout-audit: 409 passing.Per-call
window.__hyperframesLayoutAudittime, median of 5, labels on a 1920x1080 stage (Apple M4, Brave 158 as the Chromium):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.