Skip to content

perf(website): build the sidebar filter menu only when it opens - #37232

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

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

Conversation

@buluoray

Copy link
Copy Markdown
Contributor

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.

SearchDock builds 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, in SearchDock'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 first Intl.NumberFormat for 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> in website/src/pages/chat-sidebar/SearchDock.tsx now render through RenderWhenOpen, a three-line component that calls a render closure. 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 analyze of main @ 02e103f and of this branch. 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. Plain chrome-headless-shell, no DevTools connection, opens /chat?sid=perf-long cold (fresh profile, 1440x900). An inline probe reports the long tasks 6 s after load, 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; main2 is 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):

second-longest task, paired delta vs main 40 ms loopback
main2 (A/A) -5.5 ms 0 ms
this PR -16.5 ms -10 ms

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 renderSearchDock inside the shell's first-render task: 8.5 ms, 7.2 ms of it in the filter-menu children, 5.7 ms of that in new Intl.NumberFormat reached from the presets' label getter through fmtNumber.

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 opens spies on the first recent-window preset's label getter, renders the sidebar and checks it was not read while the menu is closed, then opens the menu and checks its rows render. With the SearchDock.tsx change reverted the test fails (checked).
  • Ran: vitest run src/test/ChatSidebar src/test/SearchDock (167 files, 1878 passed); tsc -b --force clean; eslint on the changed files clean; gen-ui-index --check up to date; comment-history and file-line-cap gates pass; analyze build gates pass (730 chunks within budget, no cycles).
  • Proof: not provable -- frontend test (prove.py runs Python only)

Manual verification

The filter menu opens and lists its rows in the existing filter-menu tests (ChatSidebar.crewFilterOffer, filterSuspend, hideStatusFilter and 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

  • 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 14:28
@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

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: this is a small, reversible change that defers work that only runs while the menu is closed.

Notes

  • RenderWhenOpen only works because Radix unmounts closed content. If someone later adds forceMount to FilterMenuContent, the saving disappears without any error. The new spy test covers this one menu only.

[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 .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

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of ca561b43a189f268e6cc0f7523725b9f829222e9 — 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 menu builds only when it opens, a measured cost goes away, and no helper in the repo already did this (grep for RenderWhenOpen/Lazy*Content/render={() => in website/src: 0 prior hits).

What this change ships

Inventory (3 items) — 3 justified

Intent: open the chat dashboard with a shorter main-thread first render by not building the closed sidebar filter menu. This is a FIX (perf).

  1. The sort-and-filter menu's rows (labels, counts, recent-window presets) are now built when the menu opens, not on every sidebar render. — justified
  2. A file-private RenderWhenOpen component in SearchDock.tsx runs the menu-building closure. — justified
  3. A test checks that the preset label is never read while the menu is closed and that the rows render once it opens. — justified

[FIRST-PRINCIPLES-REVIEWED] ca561b4

Description read

[DESCRIPTION-READ] 8411987ee7d79393ccd92b08739b8325f3b225b3318667ec3cb02079a39f6a3b

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 ca561b43a189f268e6cc0f7523725b9f829222e9 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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 .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

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] ca561b4

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

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

@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 ca561b43a189f268e6cc0f7523725b9f829222e9 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] ca561b4

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

@KiroCrewCaptain

KiroCrewCaptain commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: Approve

Why: 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 shell object, which stay current on every parent render. The JSX itself is unchanged. The new test spies on a preset label getter: it checks the getter isn't read while the menu is closed, and it would fail without the change. CI is green apart from unrelated Windows backend shards that were still pending, and all AI review lanes passed. The behaviour stays the same and the goal is met. Approve.

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 ca561b43a1 · 25 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@buluoray

Copy link
Copy Markdown
Contributor Author

The red Backend Tests (3.12, 3) is main's, not this PR's: test/test_conductor_agent.py::TestConductorInstaller::test_back_to_back_rounds_keep_a_spend_bound fails on main. Local runs of that one test: passes at this PR's base 02e103f and at 3bf40a9~1; fails at 3bf40a9 (#37030, "feat(conductor): look first, grill the plan, ...") and at main tip e51c773. CI runs the merge ref, so it picks the failure up from main. This PR changes two files under website/ only. I found no open issue or PR fixing it yet. Not re-running or overriding.

@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
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.
@buluoray
buluoray force-pushed the crew/kiro-crew-rust/shell-first-render branch from 3d01779 to ca561b4 Compare November 14, 2026 17:34
@buluoray

Copy link
Copy Markdown
Contributor Author

Rebased onto main 87435b5, which includes #37254 (the fix for the main red test_back_to_back_rounds_keep_a_spend_bound). No conflicts and no change to the diff. New head ca561b4. Locally: tsc clean, 198 sidebar/filter test files pass, eslint clean on the two changed files.

@github-actions github-actions Bot added readiness: checking Automated validation is still running 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 19:29

@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 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(), an expect(label).toHaveBeenCalled() would tie the spy to the menu body. Then the absence check keeps meaning something if the preset chips ever move.

@KiroCrewCaptain
KiroCrewCaptain merged commit 6664f5a into main Nov 14, 2026
99 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the crew/kiro-crew-rust/shell-first-render branch November 14, 2026 19:30
@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