Repository navigation
perf(website): build the sidebar filter menu only when it opens - #37232
Conversation
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: this is a small, reversible change that defers work that only runs while the menu is closed. Notes
[DESIGN-REVIEWED] ca561b4 Description read[DESCRIPTION-READ] b0b7f773ffc7880caf22e0b70b8596c73be38b38612ae5d72fc115650e205636 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks: the menu builds only when it opens, a measured cost goes away, and no helper in the repo already did this (grep for What this change shipsInventory (3 items) — 3 justifiedIntent: open the chat dashboard with a shorter main-thread first render by not building the closed sidebar filter menu. This is a FIX (perf).
[FIRST-PRINCIPLES-REVIEWED] ca561b4 Description read[DESCRIPTION-READ] 8411987ee7d79393ccd92b08739b8325f3b225b3318667ec3cb02079a39f6a3b That sha256 names the PR description this verdict read. Recompute it with |
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. The menu's rows, labels and behaviour are unchanged; only the moment they're built moves to when the menu opens, so there's no user-visible control to screenshot. [UX-REVIEWED] ca561b4 Description read[DESCRIPTION-READ] 457cc81e86bbcf5e5fefc6bf9e7dea32e42ba3da581c539545a9476f28b0a240 That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Code change approver recommendation: ApproveWhy: the decider estimates a 5% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes. This PR wraps the filter menu's existing children in a small RenderWhenOpen component, so the elements are built only when Radix mounts the menu content on open. FilterMenuContent and DropdownMenuContent have no forceMount, and nothing inspects the wrapped children. The moved code calls no hooks and reads values from the render function's An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
|
The red |
The session sidebar's sort-and-filter menu is about 780 lines of JSX, and SearchDock built all of it on every sidebar render, menu closed: every label's i18n lookup, the counts, and the recent-window presets, whose labels format a number and so construct the page's first Intl.NumberFormat. In a startup trace of the chat page that work sat in the dashboard shell's first render, one of the two longest tasks of the open. The menu body now renders through a small RenderWhenOpen child, so the closure runs only when Radix mounts the menu content, on open. Nothing changes once the menu is open. Measured on the chat page with a 100-row session and 222 sessions, no DevTools, paired against main with an A/A control: the shell's first render task -16.5 ms (40 ms RTT) and -10 ms (loopback), against A/A -5.5 and 0 ms. The longest task of the open is a different task and does not move.
3d01779 to
ca561b4
Compare
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approving. On head ca561b4 the review checked four things. The wrapped menu body (SearchDock.tsx:301-1086) calls no hooks, so hook order in renderSearchDock does not change. FilterMenuContent passes through to the Radix content with no forceMount, so the children still mount only while the menu is open. RenderWhenOpen gets a fresh closure on every render, so it never shows stale shell state. The new spy on the RECENT_WINDOW_PRESETS[0].label getter would fail on main, where the picker read that getter on every render. PR Readiness is green on this head.
Well done: one 3-line wrapper defers the whole subtree and leaves every line of the menu JSX untouched. The test pins the exact getter the measurements blame.
Optional:
- The comment at SearchDock.tsx:296-300 says "the longest task", but the PR body calls this render the second-longest until #37159 lands. Wording such as "one of the longest tasks" would match.
- In ChatSidebar.crewFilterOffer.test.tsx:169,
label.mockRestore()runs only if the test passes.onTestFinished(() => label.mockRestore())right after the spy would also restore it when the test fails. - After
openFilterMenu(), anexpect(label).toHaveBeenCalled()would tie the spy to the menu body. Then the absence check keeps meaning something if the preset chips ever move.
Problem / Motivation
Goal: The dashboard's first render costs less on the main thread because the sidebar's sort-and-filter menu is built only when someone opens it.
SearchDockbuilds the whole sort-and-filter menu (about 780 lines of JSX: every row's i18n label, counts, the recent-window picker) on every render of the session sidebar, while the menu is closed. Radix renders the menu content only on open, but the elements were created before that, inSearchDock's own render. In a startup trace of the chat page (no DevTools), building them took ~7-8 ms of the dashboard shell's first render, ~5.7 ms of it constructing the page's firstIntl.NumberFormatfor the recent-window preset labels.Why it matters
The key result is "longest main-thread task when the dashboard opens <= 100 ms". On the chat page the shell's first render is one of the two longest tasks (~120-130 ms), and it becomes the longest once the session-list task shrinks (#37159). Every later sidebar render also rebuilt the closed menu.
Not a goal
What changed (motivation → approach → change)
The children of
<FilterMenuContent>inwebsite/src/pages/chat-sidebar/SearchDock.tsxnow render throughRenderWhenOpen, a three-line component that calls arenderclosure. React renders it only when Radix mounts the menu content, so the closure (all the inline label lookups, counts and preset labels) runs on open instead of on every sidebar render. The JSX inside is unchanged; only its first and last lines moved into the closure.Measurements
All numbers are mine, on one shared Linux host. Builds:
vite build --mode analyzeof main @ 02e103f and of this branch. A static HTTP/1.1 server on 127.0.0.1 servesdist/;/apiis answered byscripts/lib/stub-dashboard-api.mjswith the perf fixture (scripts/lib/perf-fixture.mjs: 222 sessions, the 100-rowperf-longsession) and the websocket upgrade is accepted and left silent. Plainchrome-headless-shell, no DevTools connection, opens/chat?sid=perf-longcold (fresh profile, 1440x900). An inline probe reports the long tasks 6 s afterload, and checks the DOM on every load: the transcript's heading and 3 code blocks are present and 14 real session rows are visible, for every variant. Variants interleave each round with rotating order;main2is main served again as an A/A control; only rounds whose 1-minute load differs by less than 2 across variants are kept. 40 ms = each response delayed 40 ms.The shell's first render is the second-longest task of the open. Paired per round against main (12 rounds; 10 kept at 40 ms, 12 on loopback):
An earlier 8-round run (15 of 16 groups kept, load 4.8-14.0) gave medians of 127 -> 115 ms (A/A 131) at 40 ms and 126.5 -> 121 ms (A/A 122.5) on loopback. In the same run the longest task (the other one) did not move: +5 / +2 ms against A/A -8 / -15 ms, and FCP stayed within the A/A spread.
Profile basis: a startup trace of an unminified build, CPU samples under
renderSearchDockinside the shell's first-render task: 8.5 ms, 7.2 ms of it in the filter-menu children, 5.7 ms of that innew Intl.NumberFormatreached from the presets'labelgetter throughfmtNumber.Not measured: a real gateway, phones (the inline picker path), slower CPUs.
Backwards compatibility
Compatible: the same elements render when the menu is open; while closed they were never mounted, only created.
Removes nothing: no element, prop or export is removed.
Tests
website/src/test/ChatSidebar.crewFilterOffer.test.tsx:builds the filter menu only once it opensspies on the first recent-window preset'slabelgetter, renders the sidebar and checks it was not read while the menu is closed, then opens the menu and checks its rows render. With theSearchDock.tsxchange reverted the test fails (checked).vitest run src/test/ChatSidebar src/test/SearchDock(167 files, 1878 passed);tsc -b --forceclean; eslint on the changed files clean;gen-ui-index --checkup to date; comment-history and file-line-cap gates pass; analyze build gates pass (730 chunks within budget,no cycles).Manual verification
The filter menu opens and lists its rows in the existing filter-menu tests (
ChatSidebar.crewFilterOffer,filterSuspend,hideStatusFilterand others in the run above). Not verified by hand in a browser: the recent-window flyout on desktop and the inline picker on a phone.Screenshots / video
Why no screenshot: the closed menu was never on screen and the open menu renders the same elements; only when they are created changes.
Related Issues
N/A
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.