perf(scroll): skip the movement read a stored tree of another presentation cannot be compared with

Merged
IM
5d ago
+52-3

Summary

A directional scroll reads the default full tree afterwards to decide whether it may claim movement (#2776). surfacePairDrift never compares that read with a stored tree of another presentation, such as the interactive-only tree snapshot -i keeps. So after snapshot -i, the common agent step, every scroll paid for a capture that could only answer unobserved (baseline-presentation-drift).

planScrollMovement now compares presentation keys before the gesture and returns that same answer without the capture. It runs after the staleness checks, so their reasons still come first; a stored default tree is read and compared as before.

Before / after (iOS 27.2 simulator and Android 16 Pixel 9 emulator, Settings)

Builds taking turns on one device, 48 scrolls per build per platform, daemon-side medians:

FlowBaseHeadDelta [95% CI]
iOS scroll after snapshot -i924 ms710 ms−214 ms [−241, −177]
Android scroll after snapshot -i641 ms408 ms−234 ms [−271, −205]
iOS scroll after snapshot (control)954 ms906 mswithin noise
Android scroll after snapshot (control)606 ms596 mswithin noise

Captures per scroll: 1 → 0 after snapshot -i, unchanged after snapshot. Both builds returned unobserved for every -i scroll (60/60 per platform) and moved for the controls.

Validation

  • Base b69cf45666, head 5782a0f5e8; untraced head on both devices: -i scrolls unobserved, full-tree scrolls moved.
  • scroll-movement.test.ts: 39 passed; removing the check or moving it before the staleness checks fails a test.
  • Gate: format, lint, typecheck, layering, fallow, build, vitest-related passed.

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.