Skip to content

perf(scroll-until): build the snapshot visibility index once per pass #2528

Description

@thymikee

Waste

src/daemon/scroll-until.ts:169 evaluates .some((node) => evaluateIsPredicate(...)) per pass; predicates.ts:77 builds a fresh createSnapshotVisibility(nodes) per candidate. The rule in packages/contracts/src/snapshot-visibility.ts:135-141 (#1970) says N candidates share one index. resolveSelectorPipeline, called just above, builds an equivalent index and discards it (resolve.ts:229). N is the matched selector set (1-5), so this is not a measurable wall-clock win; it is a correctness-of-shape fix. Added in #2436.

Fix

Hoist the index out of the .some() (one per pass). Thread the pipeline's index into the predicate if the seam is already there; otherwise leave that for the H2 capture-kit move. Three lines; no measurement gate, no perf claim.

Activity

  1. thymikee commented on Sep 12, 2026

    @thymikee
    MemberAuthor

    Part of #2531.

  2. thymikee commented on Sep 14, 2026

    @thymikee
    MemberAuthor

    Shipped in #2596. Two things the premise got wrong, worth recording before this closes:

    • scroll --until resolves under the wait row, whose ambiguity is first-match. That row resolves through listSelectorChainMatches — existence-only, no visibility bookkeeping — so the index this issue pointed at in internal/resolve.ts (analyzeSelectorMatches) is never built on this path. There was no pipeline index to thread. The remaining place two indexes meet is the is path, where readUnique is fail-closed and selector-is.ts builds its own.
    • The per-candidate waste itself was real and is fixed: evaluateIsPredicate takes the capture's SnapshotVisibility instead of nodes, so a pass's candidates share one index.

    Found next to the fix and deliberately left:

    • isSelectorVisible's ambiguous and occluded arms are unreachable under the wait row (first-match, occlusion: 'ignore'). No --until test would notice either cell being flipped.
    • is computes visible for editable|selected|focused purely to fill the failure details, and computes a value nothing reads for text. That, not the index, is the per-assertion cost left on is.
    • isAssertionVisible in @agent-device/selectors and packages/maestro/src/internal/snapshot-policy.ts are one rule twice. perf(scroll-until): answer every candidate from one visibility index #2596 removed the only difference between them (nodes vs visibility), so one copy can go.
    • --until asks the candidates of the first alternative that matched, so --until A|B can keep scrolling past an on-screen B. The off-screen-twin trap, one level 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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions