Repository navigation
perf(chat): stop re-rendering the page on every keystroke and pin - #14227
Conversation
|
Intent: Keep a keystroke in the main chat composer, and a sidebar pin, from re-rendering the rest of the page, so typing stays responsive on slow CPUs and while replies stream. |
UX Review (Fable 5, fork) — ✅ PASSUX-level review of UX-Verdict: PASS Verify a draft typed during a session switch (and the Slack-link prompt hand-off) still lands in the intended session, not the one being left. [UX-REVIEWED] d870e8f Description read[DESCRIPTION-READ] a1807352e9e6dce693ed6d8029978bcdf70493ad6671c3484a1393b39c1b2579 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 |
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify the Slack-link prompt mid-switch hand-off by hand: its restore-from-prefill path is the one behavior change no listed test exercises. [DESIGN-REVIEWED] d870e8f Description read[DESCRIPTION-READ] bdb3c03871bc00a732880c875d0fcfe0145508a84f6f4ec70d78015e64887806 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 (Fable 5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Verify the Slack-link hand-off manually: mid-switch the prompt now relies entirely on the slot-change effect's prefill restore ( What this change shipsInventory (10 items) — 10 justifiedIntent: make typing and pinning stop re-rendering the whole chat page — a FIX for a measured performance defect (763→161 components/key, benchmark reproduction in the description; render-count tests added).
Lens checks run: the new store is meaningfully different from [FIRST-PRINCIPLES-REVIEWED] d870e8f Description read[DESCRIPTION-READ] 2366fc4d4838285ea761f363871568a6b7e6a41dc1635d229aa7bcabc1dc7ee1 That sha256 names the PR description this verdict read. Recompute it with |
f5126c4 to
2dce92e
Compare
Opus 5 Review (fork) — ✅ no blocking findingsReviewed |
|
|
|
2dce92e to
ec65b13
Compare
ec65b13 to
eb80340
Compare
|
|
self-added: yes
|
|
Rebased: main conflicted with this PR in @iamwhatever the rebase dropped your approval and auto-merge. Could you re-approve and re-enable auto-merge once CI is green? Thanks. |
|
CI status on b59e528. Nothing here needs a code change in this PR:
I'm not pushing again until main's reds are fixed, since a new head needs fresh run approvals and resets review. A maintainer rerun of Frontend Tests (4) and Backend Tests (3.12, 5) would help once main is green. |
|
Rebased: onto main f57c1de, whose CI is now green (the Bundle Size, Electron Shell and @iamwhatever, once CI is green could you re-approve and re-enable auto-merge? The rebase dropped both. The fork's workflow runs may also need approval first. |
|
Re-trigger with no code change: e83af4f has the same tree as 9153bdb (dc7bb55220), with a new commit date. On 9153bdb every check passed except one. Backend Tests (Windows) (2) failed with a @iamwhatever, once CI is green could you approve the workflow runs if needed, re-approve the PR and re-enable auto-merge? |
|
Rebased: e83af4f had become CONFLICTING with main after the approval, so this is now 448dd7b on main b7ad967. The only conflict was in Checked locally: @iamwhatever, the push dismissed your approval again. Once the fork's workflow runs are approved and CI is green, could you re-approve and turn auto-merge back on? Sorry for the extra round. |
|
CI status on 448dd7b: three backend shards are red, and none of the failures comes from this frontend-only diff.
I'm not pushing while main has the failure. Once main has a fix, I'll rebase and push once, which re-runs every shard, including the flaky one. |
|
Rebased: main fixed the @iamwhatever, could you approve the fork's workflow runs, then re-approve and turn auto-merge back on once CI is green? |
|
CI status on 1efddff: everything passes except two Windows backend shards. Both failed on timing assertions in backend tests that this frontend-only diff does not touch:
Both shards passed on main's CI at the same base, 631f8e6. PR Readiness is red only because of these two. I'm not pushing another same-tree commit, because it would need fresh run approvals and restart the review lanes. Could a maintainer use "Re-run failed jobs" on run 36389971127 for these two shards? @iamwhatever, once they pass, could you re-approve and turn auto-merge back on? |
|
Re-triggered CI with a same-tree push: e27ef12 has the same tree as 1efddff, with only the commit date changed. The only red checks on 1efddff were two Windows backend timing flakes, @iamwhatever, could you approve the workflow runs, re-approve the PR once CI is green, and turn auto-merge back on? Thanks. |
|
Rebased: onto main a25b321 (new head 552db76) to clear a conflict with #6511 (file-chip reconciliation) in #6511 added an effect keyed on the composer text (
@iamwhatever the push dismissed your approval again. Could you approve the workflow runs, re-approve once CI is green, and turn auto-merge back on? Thanks. |
|
Rebased: onto main 699083f with no code change (the rebase applied cleanly). The reds on 552db76 came from the base, not from this frontend-only diff:
|
|
Build Windows Installer (x64) failed on 1d7a58e (job) because the silent install went past the 120 s ceiling ( I'm not pushing again. Could a maintainer rerun that job once the Opus review finishes? After CI is green, @iamwhatever, please re-approve and re-enable auto-merge. Thanks. |
|
Rebased: main conflicted with this PR in Before pushing, @iamwhatever, could you approve the fork's workflow runs, re-approve once CI is green, and turn auto-merge back on? Thanks. |
|
CI on 1e70037: all 90 checks pass except the fork Opus 5 Review, which ended "review incomplete" after 33 minutes and posted no verdict (the Opus comment still shows the previous head's "no blocking findings"). PR Readiness is red only because of that lane. The code change since the last full Opus pass is the one-class @iamwhatever, could you re-run the Fork Opus 5 Review for this head, then re-approve and turn auto-merge back on once readiness passes? I'm holding pushes so the approvals aren't dismissed again. |
|
Rebased: main conflicted with this PR in Before pushing, @iamwhatever, could you approve the fork's workflow runs, re-approve once CI is green, and turn auto-merge back on? Thanks. |
|
CI on 93516b3: 90 checks pass, including the Opus 5 review. The one failure is Backend Tests (Windows) (5), where a single test setup errored with @iamwhatever, could you re-run the failed job in run 36534138238, then re-approve and turn auto-merge back on once readiness passes? I'm holding pushes so the approval isn't dismissed again. |
|
Rebased: main conflicted with this PR in Before pushing, @iamwhatever, could you approve the fork's workflow runs, re-approve once CI is green, and turn auto-merge back on? Thanks. |
|
CI on e082638: 91 checks pass. The one failure is Backend Tests (Windows) (1), with two tests in
This PR changes only frontend code and docs. The same two tests fail in the same shard on an unrelated PR ( I'm not pushing. Once main's Windows symlink tests are fixed, I'll rebase if needed; otherwise a rerun of that job after the fix is all this PR needs. @iamwhatever, when it's green, could you re-approve and turn auto-merge back on? |
|
Rebased onto current main to pick up #14986, which makes the two @iamwhatever, could you approve the fork workflow runs, then re-approve and re-enable auto-merge once CI is green? Thanks. |
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed on behalf of the maintainers (sweep 2026-09-29): readiness passed, required checks green on d870e8f, no blocking review threads, security posture unchanged. Approving and merging.
Problem / Motivation
Goal: Typing in the chat composer and pinning a session no longer re-render the whole page, so keystrokes land without visible lag.
Typing in the main chat re-renders most of the page on every key. A React commit probe counted 763 components rendered per keystroke on a 200-message session (3.4 commits per key), including the action menus of every visible message row. At 4x CPU throttle a keystroke took 75 ms to reach the next frame (p50, 176 ms p95), and 7 of the ~11 seconds spent typing 120 characters were long tasks. Pinning a session rendered 11,076 components, most of them sidebar row menus.
Why it matters
The composer is the surface people use most, and on slower machines or a busy page (a streaming reply, split panes) this is visible input lag. T3 Code, measured on the same host with the same harness, lands a keystroke in 17-24 ms at 4x.
Not a goal
useIsFetching, inlinedashboardConfigquery functions,i18nTlookup caching); a stacked follow-up PR covers them.What changed (motivation → approach → change)
useStateinChatPage, so each key re-renders the pageChatInputgets ~20 fresh inline callbacks and JSX props per page render, so itsmemonever holdsThe draft moves into
chat-core/composer/draftStore.ts, the P3-f step the Composer RFC plans.<Composer draft={store}>hands the store toChatInput(components/ChatInput.tsx), which reads the text withuseComposerDraftText().ChatPage(pages/ChatPage.tsx) keeps itssetInputcall shape and reads the text throughinputRefwhen it acts. Where it renders from the text, it selects one fact (blank or not, staged@dir/tokens), so it re-renders only when that fact changes;pages/chat/useChatPageSessionController.tstakes the blank-or-not flag instead of the text. The Slack-link prompt hand-off writes the composer directly only once the composer is on the target session; mid-switch, the slot-change effect restores the prompt from the prefill it already stores, so the prompt never lands in the session being left. A child component,ComposerDraftSync, mirrors the committed text intoinputRefand persists the slot draft from its effect. Child effects run before the page's own, so a keystroke batched with a slot switch still lands in the slot it was typed in.StableChatInputwrapsChatInputwithuseStableCallbackProps(page-local,pages/chat/useStableCallbackProps.ts, listed indocs/feature-map/README.mdas an internal helper), which swaps each function prop for a forwarder that calls the latest one. The composer'saboveComposercontent, session-control chips and refused-options set are memoized.hooks/useSessionControls.tsstops handing out a fresh[]and a fresh statuses map on every render, since those broke the memo chain. Inpages/ChatSidebar.tsx,SessionRowmemoizes its menu elements, re-keyed on a language change, because a row re-renders whenever its paint position moves.The ChatInput message-list subscription from the original plan is already gone on main (it reads messages at click time), so nothing changed there. Replacing every whole-slot-list selector was measured and left out:
ChatPage's own share of a pin is under 2% of rendered fibers. What remains of a pin is framer-motion's layout spring on the displaced rows plus the full slot-list push, which the sidebar-deltas work covers.Backwards compatibility
Compatible:
ChatInput'svaluebecomes optional and is still honoured without a draft root;Composeracceptsvalueas before. No persisted format changes.Tests
draftStore.test.tsx: setter shape and no-op writes; a selector caller re-renders only when its fact flips.Composer.test.tsx: under<Composer draft>,ChatInputshows and edits the store text while the host renders zero times.useStableCallbackProps.test.tsx: a memoized child skips a host render with fresh arrows, calls the latest closure, and keeps an absent handler absent.ChatSidebar.rowMemo.test.tsx: after a top insertion every displaced row re-renders but only the new row builds a context menu (42 before this change, 1 after).ChatPageDrafts.test.tsx: the effect-order guard follows the text persist intoComposerDraftSync.ChatPage.persist.integrationandChatPage.sendDuringDictation: stand-ins read the text the way the real composer does.Manual verification
Measured with the benchmark harness from the KiroCrew vs T3 Code comparison: a production build, a test-mode gateway with 67 seeded sessions, headless Chromium, three runs, medians. Same host and seed before and after.
s3000 and the empty landing chat show the same typing shape (s3000 4x p50 80 to 27 ms). 4x p50 swings between reps, so the component and busy-ms rows are the steadier comparison.
Screenshots / video
Why no screenshot: render-scheduling change only; the composer, transcript and sidebar draw the same pixels.
Related Issues
no linked issue: follow-up from the KiroCrew vs T3 Code responsiveness comparison.
Checklist