Skip to content

perf(website): mount one viewport of sidebar rows on the first render - #37159

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
crew/kiro-crew-rust/chat-first-render
Nov 14, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
crew/kiro-crew-rust/chat-first-render

Conversation

@buluoray

@buluoray buluoray commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Rendering the transcript in pieces. In the trace the 100-row transcript renders in its own task of ~85-125 ms, which is not the longest one.
  • The shell's first render (the other long task), the forced style and layout inside these tasks, and react-query's per-observer timers.
  • Changing how the observer mounts and unmounts rows after the first render, or the 1200 px margin.

What changed (motivation → approach → change)

sessionRowInitialMountBudget() in website/src/pages/chat/sessionRowWindow.tsx replaces the SESSION_ROW_INITIAL_MOUNT_BUDGET = 48 constant: 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. useSessionRowWindowRoot uses it as its default. The two tests that read the old constant now read the function; ChatSidebar.rowWindow.test.tsx had asserted the mount count with SIDEBAR_DISPLACEMENT_WINDOW, a separate number that happened to equal 48.

Measurements

All numbers are mine, from one shared Linux host. Builds: vite build --mode analyze of main @ 0403d40 and of this head (1f9ba34). A static HTTP/1.1 server on 127.0.0.1 serves dist/; /api is answered by scripts/lib/stub-dashboard-api.mjs with the perf fixture (scripts/lib/perf-fixture.mjs: 222 sessions, the 100-row perf-long session) and the websocket upgrade is accepted and left silent, as the stub's mocked socket is. Plain chrome-headless-shell with no DevTools connection opens /chat?sid=perf-long cold (fresh profile, 1440x900); an inline probe reports FCP and the longest longtask 6 s after load, and renderer PSS is read from /proc. Variants interleave in each round with rotating order; base2 is 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:

longest task 40 ms longest task loopback FCP 40 ms FCP loopback renderer PSS
main 190 ms 198 ms 858 ms 714 ms 461-467 MB
main (A/A) 190 ms 194 ms 870 ms 702 ms 462-468 MB
this PR 150 ms 169 ms 890 ms 734 ms 447-456 MB

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_BUDGET had no reader outside sessionRowWindow.tsx and its two tests, both updated.

Tests

  • website/src/test/sessionRowWindow.test.tsx: the default lane mounts exactly sessionRowInitialMountBudget() 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.
  • Ran: vitest run over the 163 ChatSidebar* and row-window test files (one failure, the displacement-window assertion above; after the update both row-window files pass, 28 tests); tsc -b --force clean; eslint on the changed files clean; comment-history and brand gates pass; analyze build gates pass (729 chunks within budget, no cycles).
  • Proof: not provable -- frontend test (prove.py runs Python only)

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

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners November 14, 2026 08:47
@buluoray
buluoray requested a review from mbriones98 November 14, 2026 08:47
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 14, 2026
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 1f9ba344028b0cc28de547076b96f8656f6faac2 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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 ships

Inventory (3 items) — 3 justified

Intent: let a person with a long session list open the chat page without a long main-thread freeze. This is an ADDITION (perf tuning).

  1. On first render, the sidebar mounts one viewport of real rows (ceil(innerHeight/52)+1) per lane root instead of 48. Rows below that start as stubs for one extra task. — justified
  2. The exported constant SESSION_ROW_INITIAL_MOUNT_BUDGET is replaced by the function sessionRowInitialMountBudget(viewportPx). It has 2 non-test callers (ChatSidebar.tsx:625 and sessionRowWindow.tsx:424), both through the hook's default. — justified
  3. Two tests now read the budget instead of SIDEBAR_DISPLACEMENT_WINDOW, the number they had wrongly used, which happened to equal 48. — justified

[FIRST-PRINCIPLES-REVIEWED] 1f9ba34

Description read

[DESCRIPTION-READ] 183952ff2d7c015d4640104abb3c6636468db280d156eaa30f9150481ae91823

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 1f9ba344028b0cc28de547076b96f8656f6faac2 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 1f9ba344028b0cc28de547076b96f8656f6faac2 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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

  • If a lane opens scrolled into its list (restored scroll, or a selected session below the first viewport), the rows in view are stubs for one task, and that is now likelier than with 48. A follow-up could start the first-viewport count at the selected row.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 1f9ba344028b0cc28de547076b96f8656f6faac2 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 1f9ba34

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 1f9ba344028b0cc28de547076b96f8656f6faac2 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 1f9ba344028b0cc28de547076b96f8656f6faac2 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 1f9ba34

Verdict parsed from the review's SHA-scoped output markers for commit 1f9ba344028b0cc28de547076b96f8656f6faac2.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 1f9ba344028b0cc28de547076b96f8656f6faac2 false-positive: <reason, 20 to 500 characters>

@buluoray

Copy link
Copy Markdown
Contributor Author

The red Backend Tests (Windows) (2) is main's: test/tracing/test_tracing_otlp.py::test_the_exit_flush_sends_spans_still_queued (assert 5 == 4) and test_a_traced_turn_reaches_a_loopback_receiver_with_its_vault_header fail because #37005 added a kirocrew.step span the tests do not expect. Tracked in #37169. This PR changes three files under website/ only. Not re-running or overriding; this PR waits for that fix. Earlier reds on this head were the installation API rate limit (each job said so); those jobs were re-run once after the reset and passed.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 14, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author

Relation to #37116 (keep the session list mounted while the sidebar is closed): no file overlap and no conflict. #37116 touches SessionsSidebarChrome.tsx, overlayRoot.tsx, useLaneScrollMemory.ts, reveal.ts and their tests; this PR touches only sessionRowWindow.tsx and two tests. git merge-tree of the two heads is clean.

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 (ChatPage.sidebarKeepMounted, ChatSidebar.rowWindow, sessionRowWindow, useLaneScrollMemory.reattach, AdoptPaneHost, ChatSidebar.folderSearch) pass on the combined tree: 71 passed.

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.
@buluoray
buluoray force-pushed the crew/kiro-crew-rust/chat-first-render branch from c794ec3 to 1f9ba34 Compare November 14, 2026 11:02
@buluoray

Copy link
Copy Markdown
Contributor Author

Rebased onto main @ 0403d40, which carries #37171 (the kirocrew.step span fix for the Windows test_tracing_otlp red my earlier comment pointed at); that part of the earlier comment no longer applies. New head 1f9ba34. Locally on this tree: test/tracing/test_tracing_otlp.py 79 passed; the two row-window test files 28 passed; tsc -b clean. The body now measures against main @ 205d08d (with #37102): longest task -39 / -36 ms, A/A +2 / -3 ms, and records the relation to #37116.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 14, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) November 14, 2026 14:27

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 (FolderBody keeps 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 closed FolderBody.
  • 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.innerHeight to 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.

@KiroCrewCaptain
KiroCrewCaptain merged commit ea114c3 into main Nov 14, 2026
145 of 153 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the crew/kiro-crew-rust/chat-first-render branch November 14, 2026 14:28
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 14, 2026
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.

2 participants