Skip to content

Studio: Images and Video strips stop re-rendering every card per thumbnail and page - #16311

Merged
danielhanchen merged 6 commits into
mainfrom
perf/r16-frontend-gallery-strip
Nov 1, 2026
Merged

danielhanchen merged 6 commits into
mainfrom
perf/r16-frontend-gallery-strip

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

What changes

Each card in the Images and Video strips was inline JSX in the page's map, so it got fresh closures for its actions menu, pin badge, click, drag and keyboard handlers on every page render. When a thumbnail landed or a page of older items was appended, the page re-rendered, and so did every card and its actions menu.

  • images-page.tsx: the card is now GalleryStripTile, a memo component. Its props are the image, its resolved thumbnail src, and booleans for selected, menu open, favorite and dragging, plus the drop cue edge.
  • video-page.tsx: the same pattern as VideoStripTile. Its props are the clip, its poster, a poster failed flag, selected, favorite, dragging and the drop cue edge.
  • Card handlers do not come in as props. Each page keeps a holder object for its whole lifetime (useState). A useLayoutEffect fills it with the page's current handlers after each commit, and the card reads it only inside event handlers. Nothing writes to a ref during render, and an action always reaches the latest page handler, so a delete, pin or archive acts on the right item after the list changes.
  • Markup, class names, attribute order, ARIA and behaviour are unchanged.
  • Three node source-contract tests now look for the strings in the new tile components.
  • Adds tests/studio/playwright_gallery_strip_renders.py and wires it into studio-frontend-ci.yml (path filters and a step).

Results

All runs use a production build, headless Chromium with 4x CPU throttle and a mocked API holding 1000 items. Each run scrolls the strip to the end, loading 20 pages and every thumbnail. Base is the merge base e4bf561a95. Arms were interleaved B, H, B, H, B, H, n = 3 each. Values are median (min to max).

Strip Metric Base Head
Images long-task total 21.8 s (19.3 to 22.0) 2.8 s (2.6 to 3.2)
Images longest task 478 ms (372 to 564) 99 ms (88 to 118)
Images frame p95 383 ms (367 to 383) 133 ms (133 to 133)
Images scroll to end 30.8 s (27.7 to 30.9) 14.1 s (13.9 to 14.2)
Video long-task total 67.6 s (64.8 to 77.6) 10.3 s (9.5 to 14.5)
Video longest task 850 ms (665 to 1738) 170 ms (130 to 244)

The base A/A spread for Images long-task total is 19.3 to 22.0 s. Every head run falls far outside it.

Render counts in the new browser check (dev build, 300 items per strip, GalleryItemMenu renders while the strip pages in):

Base Head
Images 7543 to 8144 585 to 596
Video 12000 to 12150 414 to 450

Parity, base vs head with a second base run as A/A. Captured for both strips at 7 states: initial, after 5 page appends, after selecting, menu open, after deleting a card through its menu, after pinning the card that moved into the deleted slot through its own menu, and keyboard Tab+Enter on a card's menu.

  • innerText: identical at every state.
  • ARIA snapshot: identical at every state once thumbnail loaded/loading is normalised. That state depends on network timing, and base vs base differs the same way.
  • Normalized strip outerHTML and open menu outerHTML: identical at every state.
  • Focus target after Escape: identical.
  • Screenshots: head vs base differs by 119 to 154 px on Images and 414 to 508 px on Video. Base vs base differs by 0 to 140 px and 311 to 510 px. The differing region is the same small animated area in both comparisons.

Tests

  • python3 tests/studio/playwright_gallery_strip_renders.py: fails on base (Images 7543, Video 12000 menu renders against a bound of 1200), passes on head (3 of 3 clean runs). It also deletes a card from the last page through its own menu and checks that card, and only that card, is removed. That part passes on both.
  • npm test: 14524 tests, 0 failures on head and on base.
  • npm run typecheck: passes.
  • npm run build: passes.
  • eslint and biome on the two touched pages: the same findings as base (eslint 80 errors and 15 warnings, biome 3 errors and 37 warnings, all pre-existing). biome on the three touched node tests: 20 warnings on each side, all pre-existing rules (noNodejsModules, useTopLevelRegex).
  • tests/studio/test_playwright_suites_run_in_ci.py and the other workflow contract tests: 96 passed.
  • Interaction parity on both strips, base vs head: click select, Alt+Left / Alt+Right keyboard reorder with focus kept, Enter after reorder, drag reorder, menu Favorite, menu reopen and Escape (focus return), Pin, delete of the selected tile and delete through the menu of a tile that shifted into the deleted slot. Tile order, focused element, menu text, the API calls (including after_id), normalized strip outerHTML and ARIA snapshots match at every step.
  • The right-click menu path (desktop only) was run in Chromium with the isTauri guard forced on: right-clicking two tiles opens the menu for that tile only, and delete from it removes the right tile, same as base.

Not covered

  • The desktop right-click path was not run in a real Tauri webview, only in Chromium with the guard forced on.
  • The render-count check passed 9 of 10 runs locally; the one failure was a 120 s page wait while the same host was building and serving two other vite instances.
  • Only Chromium on Linux was measured. Firefox, WebKit and the desktop webview were not.
  • Timing was measured on a shared, loaded host. The interleaving and the A/A spread control for that, but the absolute numbers are host-specific.

…bnail and page

Each strip card was inline JSX in the page's map, with fresh closures for its
actions menu, pin badge, drag and click handlers on every page render. A
thumbnail landing or a page of older items appending re-rendered the page, so
every card and its actions menu rendered again: about 26 times per card while
paging in 300 images, 40 per card for 300 videos.

The cards are now memoized components (GalleryStripTile, VideoStripTile) that
take only their own item, thumbnail, selection, menu, favorite, drag and drop
cue state. Their handlers read the page's current actions from a holder that
a layout effect refreshes after every commit, so a card re-renders only when
its own props change and an action always reaches the page's latest handler.

Rendered output is unchanged. Adds a browser check that counts card menu
renders while both strips page in, then deletes a card from the last page
through its own menu.
@danielhanchen

Copy link
Copy Markdown
Member Author

The (Python 3.13, a-f) red here is studio/backend/tests/test_streaming_stripper.py::test_prose_containing_the_word_call_is_still_amortized, a wall-clock ratio test that flaked on the runner (incremental cost grew 5.7x vs the reference's 8.6x). It is unrelated to this PR's changes. #16315 replaces the timing with a deterministic work count. A rerun of that shard should pass, and after #16315 lands it cannot flake this way.

danielhanchen added a commit that referenced this pull request Oct 31, 2026
…ead of timing it (#16315)

## Problem


`studio/backend/tests/test_streaming_stripper.py::test_prose_containing_the_word_call_is_still_amortized`
failed in `(Python 3.13, a-f)` on #16311, a frontend-only PR:

```
AssertionError: incremental cost grew 5.7x vs the reference's 8.6x on prose containing the word 'call'
```

The test timed 300 and then 1200 tokens once each and required the
stripper's growth to stay under half of the reference strip's growth.
Both measurements take a few milliseconds (about 1 ms and 4 ms locally),
so on a loaded runner the linear code read 5.7x and the quadratic
reference only 8.6x, where 4x and 16x are expected. The code under test
is unchanged on main. The timing was what flaked.

## Change

The test now counts work in the same way
`test_scan_is_amortized_not_quadratic` above it already does. It counts
the characters handed to `_first_sentinel` and to
`StreamingMarkupStripper._full_strip`, and it also asserts that the
prose comes back unchanged on every token. The counts are deterministic:

| | 300 tokens | 1200 tokens | growth |
|---|---|---|---|
| main | 13,132 | 51,832 (2.7 per buffer character) | 3.9x |
| `_first_sentinel` returning every bare `call` unconfirmed | 722,400 |
11,529,600 (600 per buffer character) | 16.0x |

The assertion requires under 8x growth and at most 8 characters of work
per buffer character.

## Verification

- The new test passes on main, and the whole file passes 67/67 three
times under `-n 4`.
- Sabotage: with the confirmation in `_first_sentinel` removed, so that
any bare `call` counts as a sentinel, the test fails with `work grew
16.0x for 4x the tokens (722400 -> 11529600 characters over a
19200-character buffer)`. That is the regression the test was written
for in #8538.
@danielhanchen

Copy link
Copy Markdown
Member Author

The Repo tests (CPU, studio) red is from this PR. tests/studio/test_model_picker_contracts.py::test_video_gallery_fetches_clips_as_their_cards_come_into_view passes on main and fails at this head (f75a9bbbe2). The test asserts "ref={stripRef}" in src and "data-clip-id={video.id}" in src over features/video/video-page.tsx. After this change, the card wrapper renders data-clip-id={id} (line 844), so the literal is gone. ref={stripRef} is still there.

The observer contract looks intact: the strip is still the observer root, and cards are still found through [data-clip-id]. Updating that assertion in this PR to accept the new spelling, for example by checking for data-clip-id={ in the card component, should make it pass. The test is in tests/studio, not studio/frontend/tests, which is probably why it was missed.

@danielhanchen danielhanchen self-assigned this Nov 1, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T10:11:25.200943Z e2de114 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 2ed4fd2f46

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen marked this pull request as ready for review November 1, 2026 09:56
# Conflicts:
#	.github/workflows/studio-frontend-ci.yml
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: e2de114cb2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit a9f51af into main Nov 1, 2026
@danielhanchen
danielhanchen deleted the perf/r16-frontend-gallery-strip branch November 1, 2026 10:45
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.

1 participant