Skip to content

perf(sdk): reduce composition paint query work - #3123

Open
leorivastech wants to merge 1 commit into
heygen-com:mainfrom
leorivastech:perf/3078-composition-paint-query
Open

perf(sdk): reduce composition paint query work#3123
leorivastech wants to merge 1 commit into
heygen-com:mainfrom
leorivastech:perf/3078-composition-paint-query

Conversation

@leorivastech

Copy link
Copy Markdown
Contributor

What

Benchmarks and reduces the per-call DOM work in compositionPaintsAt while preserving its ordering, full-bleed behavior, and lazy image-alpha sampling.

On the committed deterministic 1,000-node fixture:

Operation Before After
Rectangle reads 1,002 1,000
Computed-style reads 3,004 3
Ancestor accesses 4,000 1,005
Selector queries 2 2
Alpha reads 1 1

Fixes #3078.

Why

The paint query runs during pointer and playback updates. It previously resolved visibility and ancestor opacity eagerly for every contained candidate, reread styles during ink checks, walked ancestors again for depth, and reread root geometry for full-bleed handling.

Those repeated DOM reads dominate the query on large compositions and can interleave with animation writes.

How

  • Defers visibility resolution until candidates are visited in the existing sorted order.
  • Caches computed styles, rectangles, depth, and ancestor opacity for one invocation only.
  • Reuses cached style and geometry during image-alpha sampling and full-bleed handling.
  • Keeps the exact area asc, depth desc sort so a transparent minimum can fall through without eager alpha sampling.
  • Avoids persistent document caches because roots can move or transform between frames.
  • Uses iterative ancestor memoization so deeply nested DOM does not introduce recursion limits.

Test plan

  • Unit tests added/updated
  • Manual testing performed — a trustworthy wall-clock Chromium run was not available in my environment; the committed benchmark uses deterministic DOM-operation counts instead of timing as the stable regression gate
  • Documentation updated (not applicable; internal SDK performance change)

Verified:

  • Full SDK suite: 546 passed
  • Focused iframe suite: 102 passed
  • SDK typecheck and build
  • oxlint, oxfmt, git diff --check, and all pre-commit hooks

Regression coverage also verifies a moving root is observed across calls, a non-painting minimum falls through to the next candidate, alpha sampling stays at one read, and a 12,000-level ancestor chain does not overflow the stack.

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.

perf(sdk): benchmark and reduce the per-call cost of the paint walk

1 participant