Repository navigation
Studio: Images and Video strips stop re-rendering every card per thumbnail and page - #16311
Conversation
…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.
|
The |
…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.
|
The The observer contract looks intact: the strip is still the observer root, and cards are still found through |
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
# Conflicts: # .github/workflows/studio-frontend-ci.yml
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
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 nowGalleryStripTile, amemocomponent. Its props are the image, its resolved thumbnailsrc, and booleans for selected, menu open, favorite and dragging, plus the drop cue edge.video-page.tsx: the same pattern asVideoStripTile. Its props are the clip, its poster, a poster failed flag, selected, favorite, dragging and the drop cue edge.useState). AuseLayoutEffectfills 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.tests/studio/playwright_gallery_strip_renders.pyand wires it intostudio-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).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,
GalleryItemMenurenders while the strip pages in):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.outerHTMLand open menuouterHTML: identical at every state.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.noNodejsModules,useTopLevelRegex).tests/studio/test_playwright_suites_run_in_ci.pyand the other workflow contract tests: 96 passed.after_id), normalized strip outerHTML and ARIA snapshots match at every step.isTauriguard 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