Skip to content

perf(SnapPaging): a settle samples its curve once, not once per item - #10568

Merged
cixzhang merged 4 commits into
meta:mainfrom
vjeux:perf/snap-paging-settle-copies
Nov 8, 2026
Merged

cixzhang merged 4 commits into
meta:mainfrom
vjeux:perf/snap-paging-settle-copies

Conversation

@vjeux

@vjeux vjeux commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

User impact

A snap-paging Carousel's lift took 36.2 ms of main thread at 4× CPU with 9 items (two dropped frames on a low-end phone), 66.2 ms with 30; UIKit's takes none.

Problem and solution fit

Every item's animator sampled the pager's curve into the same keyframes: 3,710 curve reads per settle with 9 items, 12,320 with 30. Now a call reuses keyframes an earlier call in its task baked from the same curve objects, offset and rest values, or else only their sample times. Snap paging plays the settle only on the lead and items that can show.

Expected behavior and authority

spec:AST-094 FR5: a release advances at display rate on the compositor; component:Carousel FR7 settles as FR6 says.

Smallest restoration

  • animator.ts: a per-task cache of baked keyframes and sample times, keyed by play's curve objects; a hit copies its effect, and each item keeps its own animator.
  • SnapPaging: which items can show comes from the curve and the items' spans, re-read on a resize under a held finger. A measure or a stop puts the other items where the lead is.
  • The three-up story takes hasLoop.

Evidence

  • Reproduction before the change: on the base arm, 9 bakes per settle; a caught row leaves items apart.

  • Result after the change: 1 bake, 490 curve reads per settle, with 9 or 30 items. Every item in view animates on its own layer, from the lead's start and at its translate; a caught row puts each at the lead's translate.

  • Regression test or other mutation-sensitive proof: seven mutants each fail their test, and the copies head fails the layer check.

  • Cost, the lift's task in Chromium, median of 5:

    Items Build 1× CPU 4× CPU
    9 main 8.4 ms 36.2 ms
    9 this change 5.0 ms 24.4 ms
    30 main 14.3 ms 66.2 ms
    30 this change 5.3 ms 25.0 ms

    Over a frame at 4×; flat in item count.

  • Representative unchanged path: the drag, and Reduce Motion's resting stop (items out of view skip their cross-fade).

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

  • Merged with main 72968ac: SnapPaging.ts takes main's end-page skip (fix(SnapPaging): a stop within half a step of the end is the end page #10591), and stops() aligns the left-out items, then reads pages().stops. At that head: the settle spec ×3, Chromium 24 of 24 and WebKit 24 of 24; fix(SnapPaging): a stop within half a step of the end is the end page #10591's SnapPaging spec, Chromium 43 passed and 5 skipped, WebKit 48 passed; Carousel and SnapPaging specs, Chromium 59 passed and 5 skipped, WebKit 63 passed and 1 skipped; units 2,073; typecheck 0; strict lint 0 errors. The results below are at bdfb6b8, before the merge.
  • Units for SnapPaging, Carousel, hooks and motion: 97 files, 2,059 tests pass. Two new animator tests, three calls sharing one bake and a call with other rest values keeping its own keyframes at the shared times, fail on the base arm's animator. A third, a curve played and rebased in one task baking the shifted keyframes, fails on fba753c. Core UI suite (pnpm test:ui): 920 files, 22,570 tests pass.
  • The new spec, eight tests: Chromium (a 2-thread pin, 1 worker) ×5, 40 of 40; WebKit (CI-profile container) ×10, 80 of 80. While the lead settles, each item in view, as the lead places it, has its own running animation from the lead's start, or rests at the settle's end. Each animating item has will-change: translate, and each item in view is within 0.01 px of the lead's translate. WebKit reads an accelerated animation at each read's own time, so the check reads the lead before and after the items and skips a frame whose lead moved.
  • Mutants, not for landing, ×3 in each engine: every call bakes its own keyframes fails the count; only the start and end views play fails the wrap; a stop that leaves each item where it stopped fails the catch in Chromium 1 of 3 and WebKit 1 of 3; a resize that keeps the row width and the item spans fail the widened and narrowed rows; a measure that reads the left-out items where they were left fails the second flick. Each frame callback reading its own time fails the start check in 6 of 8 tests in Chromium, and in 4 in WebKit. The copies head f6b17a5 fails the layer check on a press from rest, in both engines. The base arm, main's product under this change's tests and story, fails the count and the one-view tests in both engines ×2, and the catch in 1 of 2 runs in each.
  • Probes: curve reads per settle count every at call on the pager's curve (main's arm); the lift's touchend task from a trace, 5 runs each, 30 items cloned from the story's 9; Reduce Motion's settle, 2 runs each.
  • Carousel and SnapPaging interaction specs: Chromium 52 passed, 5 skipped; WebKit 56 passed, 1 skipped. Motion interaction specs, on the same animator: Chromium 151 passed; WebKit 144 passed, 7 skipped.
  • Typecheck 0; CI=true pnpm lint 0 errors; pnpm check:knowledge passes; Changeset coverage passes.

@vercel

vercel Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 8, 2026 10:03am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 7, 2026
@astracat-bot

astracat-bot Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 8, 2026, 10:20 AM UTC

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 503b493

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC
DateInput 183.2 kB (+533 B) · 16.7 kB CSS (0) —
BottomSheet 66.1 kB (+525 B) · 7.5 kB CSS (0) —
TimeInput 158.9 kB (+519 B) · 15.7 kB CSS (0) —
32 more components
Component Size LoC
DateTimeInput 205.0 kB (+516 B) · 18.4 kB CSS (0) —
PowerSearch 282.9 kB (+510 B) · 23.6 kB CSS (0) —
Lightbox 118.3 kB (+505 B) · 10.4 kB CSS (0) —
lab/Comments 337.6 kB (+493 B) · 2.5 kB CSS (0) —
Switch 101.1 kB (+490 B) · 9.9 kB CSS (0) —
lab/NavigationScreen 80.5 kB (+489 B) · 1.5 kB CSS (0) —
lab/TabBar 75.2 kB (+489 B) · 1.8 kB CSS (0) —
lab/NavigationStack 80.5 kB (+488 B) · 1.5 kB CSS (0) —
lab/CommentThread 330.6 kB (+478 B) · 2.4 kB CSS (0) —
SideNav 111.3 kB (+476 B) · 11.3 kB CSS (0) —
lab/CommentComposer 147.6 kB (+466 B) · 1.9 kB CSS (0) —
SegmentedControl 93.0 kB (+463 B) · 6.8 kB CSS (0) —
Popover 88.3 kB (+462 B) · 13.9 kB CSS (0) —
ChatLayout 79.7 kB (+459 B) · 10.4 kB CSS (0) —
lab/ChatEmojiPicker 102.8 kB (+446 B) · 773 B CSS (0) —
Slider 106.5 kB (+443 B) · 8.8 kB CSS (0) —
lab/ChatReactionBar 103.9 kB (+441 B) · 1.1 kB CSS (0) —
lab/PageControl 73.5 kB (+429 B) · 709 B CSS (0) —
lab/TourStep 94.6 kB (+409 B) · 590 B CSS (0) —
ContextMenu 106.2 kB (+1 B) · 17.0 kB CSS (0) —
Pagination 108.3 kB (+1 B) · 17.5 kB CSS (0) —
Table 116.3 kB (+1 B) · 17.7 kB CSS (0) —
Markdown 179.5 kB (0) · 20.0 kB CSS (0) —
MoreMenu 95.9 kB (0) · 17.1 kB CSS (0) —
MultiSelector 93.4 kB (0) · 16.6 kB CSS (0) —
Selector 98.2 kB (0) · 17.1 kB CSS (0) —
TableHeaderCell 107.0 kB (0) · 17.2 kB CSS (0) —
Tokenizer 90.1 kB (0) · 18.4 kB CSS (0) —
lab/TabBarItem 3.8 kB (0) · 1.8 kB CSS (0) —
richtext/RichTextEditorToolbar 250.8 kB (0) · 454 B CSS (0) —
DropdownMenu 95.6 kB (−1 B) · 17.1 kB CSS (0) —
TableCell 107.4 kB (−1 B) · 17.4 kB CSS (0) —

Package size: @astryxdesign/core 7.00 MB packed (+3.6 kB); no new dependencies.

API changes: none in this pull request

Committed API report behind this build: cli 29 rows, core 35 rows; run pnpm api:report.

Not run on this PR: add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes: the settle copies cut the release's work and keep the items in step (the new frame checks pass on this head and fail on main), but they run beside the shared animator instead of through it.

  • SnapPaging.ts plays every item after the first through local Web Animations copies (startedOn, copyToChildren, alignToLead) that re-implement the animator's start dating outside its start group and skip its layer promotion, so on an edge-button press from rest the copied items get no will-change for the whole settle; extend the animator so one play bakes once and drives several targets, and call that instead.

Two optional comment wording suggestions are inline.

[Automated review]

@vjeux
vjeux force-pushed the perf/snap-paging-settle-copies branch from f6b17a5 to fba753c Compare November 7, 2026 22:23
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Nov 7, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes: the settle now bakes once inside the shared animator and every item keeps its own animator, start and layer, which settles the earlier copy-path concern, but the new keyframe cache misses one case.

  • rebase keeps a played curve's source when it shifts the segment (the non-spring branch in motion/animator.ts), and the new task-bake key compares only source, offset and duration, so a curve that is played and rebased in the same task replays its unshifted keyframes and then jumps by the rebase delta when it retires; dropping source from the rebased segment and adding a unit test that plays and rebases in one task fixes it.

This review covers the whole diff against main, #10584's commits included, because #10584's description does not carry the same Stack: line. Two optional comment wording suggestions are inline.

[Automated review]

Comment thread packages/core/src/motion/animator.ts Resolved
Comment thread packages/core/src/motion/animator.ts Resolved

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes: the rebase fix and both comment suggestions are in, and the settle now bakes once while every item keeps its own animator, but leaving items out of the settle breaks how the row is measured while it settles.

  • Miss: a second flick that lands on a running settle makes the pager remeasure the row while the left-out items still sit at their release translate, so span(), spansOf() and the stops read in SnapPaging.ts see their edges off by the distance the lead has moved, and on the three-up story two flicks toward the end rest on items 6–8 or back on items 1–3 instead of a view page (main rests on a page every time); measuring each item net of its own translate relative to the lead, or placing the left-out items at the lead before measurePages reads them, plus a settle-spec case that flicks again mid-settle, would fix it.

[Automated review]

A settle played the pager's curve on every item, and each item's
animator sampled the same curve into the same keyframes. The animator
now reuses the keyframes that an earlier call of the same task baked for
the same curve objects, offset and rest values, and copies their effect.
With other rest values it reuses only the sample times. Snap paging
plays the settle on the lead and on the items that can show during it,
and a stop puts every item of a held row where the lead stopped. Before
the row is measured, the items the settle left out take the lead's
translate. The three-up paging story takes hasLoop, so a press past the
last page sweeps every page.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: CI has not run on this head yet; it runs once the pull request leaves draft and a maintainer adds the ci:run label.

A second flick during a settle now rests on a view page, as it does on main, and the shared bake, the culling and the catch alignment hold in right-to-left, under Reduce Motion and through a resize mid-settle. One non-blocking comment wording suggestion is inline.

[Automated review]

@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 8, 2026
@vjeux
vjeux marked this pull request as ready for review November 8, 2026 03:04
vjeux added 2 commits November 7, 2026 19:13
SnapPaging.ts takes main's end-page skip and pages(): stops() aligns
the items a settle left out, then reads pages().stops.
@cixzhang

cixzhang commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

/approve-spec f579ad9

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved: this head only merges main and takes the last comment suggestion, and the settle bake and culling still hold beside main's split-end pages, in both directions and through a touch that catches a settle.

CI's WebKit interaction shard 1/6 is red on two tests: this change's widened-row settle test hit the harness's frame-starvation error (no frame for 555 ms, which the harness says proves nothing), and a harness test that main has since updated failed. The widened-row test passes 10 of 10 in WebKit on this head and every other shard is green, so please update the branch onto main and re-run that shard; the pull request can merge once the required checks pass.

[Automated review]

@cixzhang

cixzhang commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 503b493

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved: the head only merges main, which changes none of this pull request's files, and CI is green on it.

The settle proofs pass on main's reworked touch harness in Chromium and WebKit, including the WebKit interaction shard that failed before.

[Automated review]

@cixzhang
cixzhang merged commit 2d7a3bc into meta:main Nov 8, 2026
78 checks passed
@vjeux
vjeux deleted the perf/snap-paging-settle-copies branch November 8, 2026 20:31

This branch was successfully deployed

1 active deployment
Preview — 503b4937 Deployed Nov 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants