Skip to content

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

Closed as not planned

Description

@hblee12294

Deferred from #3070 (thread), where the fix was judged to want a benchmark rather than eyeballing.

compositionPaintsAt is an uncached O(all stamped elements) walk, and the documented host recipe re-runs it on pointer movement and on every frame (animated artwork moves under a stationary cursor). Per call, per contained candidate:

  • querySelectorAll + getBoundingClientRect on every stamped element — ensureHfIds stamps every body descendant, so addressableOnly barely shrinks it
  • up to three getComputedStyle resolutions (isRenderedVisible, isOpacityVisible's inclusive re-read, styleInk)
  • an eager full ancestor opacity walk plus a second depthOf ancestor walk
  • a fresh root query per painted hit when fullBleedFraction > 0

On a ~1000-element composition that is order 100k rect/style reads per second, forcing layout flushes interleaved with GSAP's writes — janking the animation the overlay sits on.

Semantics-preserving wins identified in review:

  • read computed style once per candidate and thread it through
  • defer the visibility check into the lazy find predicate beside the ink test
  • single-pass min-tracking instead of a full sort
  • cache frame area per document

Why this needs a benchmark, not a patch. Two of those interact with the lazy-sampling property pinned by samples alpha lazily — the smallest painting box wins before the rest are read: deferring visibility changes how many candidates get style-resolved, and replacing the sort with min-tracking changes the order ink is evaluated in. Both are safe on paper and both could quietly cost more alpha samples than they save. Measure on a ~1000-element composition before and after.

The host-side half already landed in #3070: the guide now says to coalesce pointer / Alt / playhead into one gated rAF query and to short-circuit before the walk when the pointer is outside the composition's box.

Activity

  1. leorivastech commented on Aug 8, 2026

    @leorivastech
    Contributor

    I'd like to take this. I have a deterministic 1,000-node benchmark plus a semantics-preserving optimization that caches DOM reads per invocation, defers visibility work, reuses root geometry, and keeps the existing area/depth order and lazy alpha sampling. I'll open the focused PR shortly with before/after operation counts and regression tests.

  2. miga-heygen commented on Sep 16, 2026

    @miga-heygen
    Contributor

    Closing during backlog triage: no measured user-facing regression is attached. If a composition shows the paint walk dominating render time, please open a report with the profile and we will pick it up.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions