Repository navigation
perf(website): mount one viewport of sidebar rows on the first render - #37159
Conversation
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The one change is a measured performance tuning inside the existing row window. The observer, the stubs and the 1200 px margin stay as they were. What this change shipsInventory (3 items) — 3 justifiedIntent: let a person with a long session list open the chat page without a long main-thread freeze. This is an ADDITION (perf tuning).
[FIRST-PRINCIPLES-REVIEWED] 1f9ba34 Description read[DESCRIPTION-READ] 183952ff2d7c015d4640104abb3c6636468db280d156eaa30f9150481ae91823 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 diff adds and changes no control, label or state; it only mounts fewer offscreen sidebar rows on first render. [UX-REVIEWED] 1f9ba34 Description read[DESCRIPTION-READ] 94668eb1bae1c9025fa4875651ccf58446425ebd7f087cd3a0d432707f8ce27d 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 |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: a reversible, one-function change to a first-render budget, backed by an A/A-controlled measurement; nothing outside the patch reads the removed constant. Notes
[DESIGN-REVIEWED] 1f9ba34 Description read[DESCRIPTION-READ] de9682789ed4f4836d293c3e19a9dca4f94b65b422c8c9407dd080f7cf8293cc 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 |
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: |
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: |
|
The red |
|
Relation to #37116 (keep the session list mounted while the sidebar is closed): no file overlap and no conflict. #37116 touches Behaviour together: this PR changes only how many rows mount on a lane root's first render. #37116 keeps the list mounted across close and reopen, so a reopen is not a first render and the budget does not apply to it; the rows it shows come from the observer, as before. Checked on a build with both changes (#37116 @ 5b70d74 plus this commit), against #37116 alone, with the stub API and the 222-session fixture, headless Chromium 1440x900, two runs each: after open both show 32 real rows (14 visible) and 82 stubs; hide then show the sidebar, and on the first animation frame after the click both show 32 real rows and 0 visible stubs; 1.5 s later the same. Both PRs' tests ( |
Opening the chat page with a long session list, the longest main-thread task is the sidebar's first render once the session list arrives. Each session row is expensive to mount (a react-query observer, store subscriptions, a dnd-kit draggable and droppable, a Framer motion node, two Radix menus), and the lane mounted 48 rows up front, about two viewports, before its IntersectionObserver had reported anything. The first render now mounts one viewport of rows (ceil(innerHeight / 52) + 1, 19 at 900 px). The rows below start as the existing same-height stubs and mount on the observer's first delivery, in a later task. Measured on the chat page with a 100-row session and 222 sessions, no DevTools, paired against main with an A/A control: longest task -56 ms (40 ms RTT) and -33 ms (loopback); FCP within the A/A spread.
c794ec3 to
1f9ba34
Compare
|
Rebased onto main @ 0403d40, which carries #37171 (the |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approving. On this head the review read the whole diff of all 3 files. It confirmed that the removed SESSION_ROW_INITIAL_MOUNT_BUDGET has no reader left, that both production callers of useSessionRowWindowRoot (ChatSidebar and SessionRowWindowScroller) pick up the new viewport-sized default, and that rows past the budget fall back to the existing same-height stubs, which keep identity, focus and click forwarding. It also checked that reverting the default to 48 reds the new tests (budget 16 against N=78 under the 768px test window), and that no other open PR reads the removed constant. PR Readiness is green.
Done well: the measurement uses interleaved rounds with an A/A control on main, and the ChatSidebar test now reads the real budget, not a number that only happened to equal 48.
- Optional: rows inside collapsed folders and crew groups stay mounted and claim budget positions first (
FolderBodykeeps its children mounted), so the visible rows below them can paint as stubs for one task. A follow-up could skip budget positions inside a closedFolderBody. - Optional: a lane restored into its list (scroll memory after a sidebar collapse, or a selected row below the first viewport) shows stubs for one task. One sentence under Backwards compatibility would cover it. "Manual verification" also mentions before/after screenshots that are not attached to the PR.
- Optional: add one test that stubs
window.innerHeightto 900 and expects exactly 19 mounted rows as a literal, so the viewport source itself is pinned. Naming the 52px row height as a constant would also help.
Problem / Motivation
Goal: Opening the chat page with a long session list blocks the main thread for less time: the sidebar's first render mounts only the rows the reader can see.
When the chat page opens, the session sidebar's first render mounts 48 session rows per lane before its IntersectionObserver has reported anything: about two viewports, at 900 px tall about 35 more rows than are visible. Each row is expensive to mount (a react-query observer, store subscriptions, a dnd-kit draggable and droppable, a Framer motion node, two Radix menus; see the WHY note in
sessionRowWindow.tsx). In a startup trace of the chat page with 222 sessions (no DevTools), that render is one task of ~200-250 ms, and with #37102's compile hints applied it is the longest task of the open.Why it matters
The key result is "longest main-thread task when the dashboard opens <= 100 ms". Input during that task waits. People with many sessions pay the most.
Not a goal
What changed (motivation → approach → change)
sessionRowInitialMountBudget()inwebsite/src/pages/chat/sessionRowWindow.tsxreplaces theSESSION_ROW_INITIAL_MOUNT_BUDGET = 48constant: one viewport of rows,ceil(innerHeight / 52) + 1(19 at 900 px, 29 at 1440 px), sized at the shortest common row so a lane of two-line rows still fills its viewport with real rows. Rows below that start as the existing same-height stubs, which carry the same DOM identity attributes, and mount on the observer's first delivery, which comes in a later task.useSessionRowWindowRootuses it as its default. The two tests that read the old constant now read the function;ChatSidebar.rowWindow.test.tsxhad asserted the mount count withSIDEBAR_DISPLACEMENT_WINDOW, a separate number that happened to equal 48.Measurements
All numbers are mine, from one shared Linux host. Builds:
vite build --mode analyzeof main @ 0403d40 and of this head (1f9ba34). 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, as the stub's mocked socket is. Plainchrome-headless-shellwith no DevTools connection opens/chat?sid=perf-longcold (fresh profile, 1440x900); an inline probe reports FCP and the longestlongtask6 s afterload, and renderer PSS is read from/proc. Variants interleave in each round with rotating order;base2is main served again as an A/A control; only round groups whose 1-minute load differs by less than 2 are kept. 40 ms = each response delayed 40 ms.Base: main @ 0403d40 (this PR's merge base, carrying #37102's compile hints). Both builds checked in the probe before counting: the transcript renders (its heading and 3 code blocks are in the DOM, 9788 characters of page text) and 14 real session rows are visible in the sidebar, on every load of every variant. 8 rounds, 14 of 16 groups kept, load 6.3-10.8:
Paired against main: longest task -44 / -34 ms, against A/A 0 / -1 ms; FCP +28 / -4 ms, against A/A +16 / -14 ms, inside the spread. Renderer memory is 11-14 MB lower, from the rows that are no longer mounted. A run on main @ 205d08d gave the same picture (-39 / -36 ms, A/A +2 / -3 ms).
Profile basis (startup trace, unminified build with hints): in the sidebar task, self time sits in React's commit work for the mounted rows, react-query observer timers, i18n and relative-time formatting per row, and forced layout. A 16-row trial budget took that task from ~255-296 ms to ~158-165 ms traced; the shipped budget at 900 px is 19.
Not measured: a real gateway, a long list with folders collapsed, mobile (the drawer), slower CPUs.
Backwards compatibility
Relation to #37116 (keep the session list mounted while the sidebar is closed): no shared files and no merge conflict. This PR only changes how many rows mount on a lane root's first render; with #37116 a reopen is not a first render, so the rows shown on reopen still come from the observer. A build with both changes and a build with #37116 alone behave the same on open, hide and show: 32 real rows (14 visible), and 0 visible stubs on the first frame after reopening.
Compatible: rows past the first viewport already started as stubs whenever the observer had not reported yet; the change only lowers how many start live. Every row keeps its slot and identity attributes in the DOM.
Removes nothing:
SESSION_ROW_INITIAL_MOUNT_BUDGEThad no reader outsidesessionRowWindow.tsxand its two tests, both updated.Tests
website/src/test/sessionRowWindow.test.tsx: the default lane mounts exactlysessionRowInitialMountBudget()rows; the budget is 19 at 900 px, 29 at 1440 px, 1 at 0.website/src/test/ChatSidebar.rowWindow.test.tsx: the stubbing and identity cases read the budget instead of the displacement window.vitest runover the 163ChatSidebar*and row-window test files (one failure, the displacement-window assertion above; after the update both row-window files pass, 28 tests);tsc -b --forceclean; eslint on the changed files clean; comment-history and brand gates pass; analyze build gates pass (729 chunks within budget,no cycles).Manual verification
Screenshots of the chat page before and after (headless, same fixture): the same layout, the visible sidebar rows are real rows, and the transcript is scrolled to the bottom on both. Not verified: dragging a session onto a stubbed row in the first second after open.
Screenshots / video
Why no screenshot: only rows below the visible part of the sidebar start as stubs for one extra task; the visible page is the same, as the before/after screenshots compared above show.
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.