Skip to content

perf(web): compile ChatPaneNotices with the React Compiler - #23899

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:perf/react-compiler-chat-pane-notices
Oct 25, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:perf/react-compiler-chat-pane-notices

Conversation

@Pearcekieser

@Pearcekieser Pearcekieser commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Stop the chat pane's notices from re-rendering on every frame of a streaming reply.

ChatPaneNotices passes a new onDismiss arrow to each ErrorNotice on every render. While a reply streams into the open chat, that makes ErrorNotice render about 10,100 times in 30 s on desktop, and about 7,100 times on mobile at 4x CPU throttle.

Why it matters

Those renders run on the main thread during the stream, the busiest time for the chat page. They change nothing on screen. This is the first component on the React Compiler opt-in list, so it also shows that the list, the bailout test and the per-file lint work on a real file.

Not a goal

  • Changing what any notice shows or when it shows.
  • Compiling other components. Each one gets its own PR.
  • Fixing the other render sources on the stream path, such as the TagPopoverProvider context value behind MdParagraph.

What changed (motivation → approach → change)

The render-cause classifier in the render benchmark attributed 7,466 of 9,810 ErrorNotice renders in the S2 stream scenario to a changed onDismiss prop, and 5,432 of them to ChatPaneNotices as the parent. ChatPaneNotices.tsx already compiles with no bailout, so this PR only adds it to website/react-compiler.config.mjs. The compiler then memoizes the handlers and the notice elements.

Adding it to the list also turns on the bailout test for this file and the compiler-backed react-hooks lint rules, so a later edit that makes it bail fails CI.

The compiler memoizes each value on the reactive inputs it reads. i18nT() and fmtDate() read the active catalog without being inputs, so compiling the file as it was would keep a visible notice in the previous language after a language switch. The component now builds every translated string in one paneCopy() call that takes useLanguageGeneration() as an argument, so a switch rebuilds the strings. A compiled component also caches the elements it renders while their props are unchanged, so each child becomes a memo boundary on a language switch. ErrorNotice and VoicePlaybackNotice (in website/src/components/) and UnrestoredTabsNotice translate their own text, so each now calls useLanguageGeneration(), the repository's existing subscription for memo boundaries. It schedules the child's own re-render on a switch without remounting it. ErrorBoundary is a class component and cannot call the hook, so it gains an optional languageGeneration prop. The pane passes the generation, which changes the boundary element on a switch and re-renders a visible crash card without resetting it.

The allowlist test gains two checks. A listed file that imports i18n/t or i18n/format must call useLanguageGeneration(). Every relative .tsx module a listed file imports, statically or through a lazy import(), that translates must call it too, apart from ui.tsx, whose Btn renders no catalog text. For ErrorBoundary the check instead requires every <ErrorBoundary> in a listed file to pass languageGeneration.

Backwards compatibility

Compatible: the component's props and rendered output are unchanged. Its strings are built in one call, and its memoization changes.

Removes nothing: the diff adds one entry to the opt-in list, moves the pane's string building into one function, adds a language subscription to three notice components and an optional prop to ErrorBoundary, and adds tests.

Tests

  • src/test/reactCompilerAllowlist.test.ts now compiles ChatPaneNotices.tsx and fails on any bailout.
  • src/test/ChatPaneNotices.languageSwitch.test.tsx renders the compiled component, switches to zh-CN and re-renders with identical props. It expects the config notice and the pane's dismiss labels in Chinese, and the upload-error ErrorNotice dismiss label, whose props hold no translated string, in Chinese too. It fails with the pane's strings left as they were, and fails again with ErrorNotice unsubscribed. It passes here.
  • src/test/ChatPaneNotices.crashCardLanguage.test.tsx makes the lazy unrestored-tabs notice throw so the pane's crash card shows, switches to zh-CN with identical props, and expects the card heading in Chinese. It fails when the pane omits languageGeneration on the boundary and passes here.
  • The allowlist test's two new checks fail a listed file that translates without useLanguageGeneration(), and a translating child of a listed file that does not subscribe or, for ErrorBoundary, is not passed the generation.
  • The 3 test files that reference ChatPaneNotices run against the compiled component: 44 tests across 5 files pass. The 140 test files that reference ErrorNotice, UnrestoredTabsNotice or VoicePlaybackNotice pass, 4,728 tests. The 24 test files that reference ErrorBoundary or ChatPaneNotices pass with the new prop, 481 tests. The new tests passed 3 shuffled runs.
  • Proof: not provable -- frontend test

Manual verification

Render benchmark (the P8 script from #23431), medians of 3 interleaved runs, 30 s windows. Column A is main with the opt-in list empty, column B is this PR.

Scenario Metric A B
S2 desktop ErrorNotice renders 10,126 [10,099-10,147] 4,544 [4,524-4,559]
S2 desktop all renders 395,409 [394,182-396,022] 386,994 [386,608-388,944]
S2 desktop script ms 15,411 [14,989-16,233] 15,133 [14,855-16,065]
S2 mobile 4x ErrorNotice renders 7,130 [7,082-7,305] 2,480 [2,452-2,570]
S2 mobile 4x all renders 176,146 [174,629-180,890] 166,629 [166,153-170,864]
S2 mobile 4x script ms 25,198 [25,151-25,316] 25,129 [25,006-25,630]
S1x5 desktop ErrorNotice renders 643 [643-680] 519 [489-519]
S1x5 desktop all renders 46,894 [46,894-49,657] 49,427 [46,674-49,427]

Total renders fall 2.1% on desktop S2 and 5.4% on mobile S2, with ranges that do not overlap. S1x5 total renders take the same two values in both variants, so that row is noise. Script time, dispatches and selector calls are unchanged within the spread. These numbers were measured before the language fix. It adds one useSyncExternalStore subscription per notice that only fires on a language switch, so it does not change when the notices re-render during a stream.

Screenshots / video

Why no screenshot: the notices render the same elements; only how often they re-render changes.

Related Issues

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

@Pearcekieser
Pearcekieser requested review from a team and KiroCrewCaptain as code owners October 25, 2026 02:01
@Pearcekieser
Pearcekieser requested a review from buluoray October 25, 2026 02:01
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 25, 2026
@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 3301a77c779c2fef1cbbcc17c118ea59d59f7384 via the fork AI-review pipeline — 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

No blocker. The only note is that the allowlist's first new check is a second form of a check the memo ratchet already makes.

Notes

  • Item 5 — duplicate of website/src/test/MemoI18nSubscriptionRatchet.test.ts: the new check "%s makes the language an input when it translates" rebuilds that ratchet's branch-1 rule (a file that translates must call useLanguageGeneration()) with its own regex, /from '[./]*i18n\/(t|format)'/. The ratchet already exports scanFile, and its trigger also covers i18next.language reads and wrapper modules. Subtraction: delete the new it.each and treat REACT_COMPILER_FILES as boundaries inside the existing ratchet's scanFile loop, so the rule is written once.

What this change ships

Inventory (6 items) — 5 justified

Intent: stop the chat pane's notices from re-rendering on every frame of a streaming reply. This is a perf FIX.

  1. ChatPaneNotices is compiled by the React Compiler, so ErrorNotice renders drop by about 55–65% while a reply streams — justified
  2. The pane's translated strings are built in one paneCopy() call keyed on the language generation, so a language switch rebuilds them — justified
  3. ErrorNotice, VoicePlaybackNotice and UnrestoredTabsNotice subscribe to language switches on every page that uses them — justified
  4. ErrorBoundary takes an optional languageGeneration prop, so a visible crash card follows a language switch — justified
  5. The allowlist test fails a listed file that translates without subscribing — duplicate of MemoI18nSubscriptionRatchet.test.ts branch 1
  6. The allowlist test fails a listed file whose imported child translates without subscribing, with an exemption list and a prop list — justified

[FIRST-PRINCIPLES-REVIEWED] 3301a77

Description read

[DESCRIPTION-READ] cce2699411293ff152bce519b77512e90989148ee8e8c8ff45c70bdf725ab246

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 Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ✅ PASS

UX-level review of 3301a77c779c2fef1cbbcc17c118ea59d59f7384 via the fork AI-review pipeline — 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 user-visible control. Every notice renders the same strings and elements, with only the compiler memoization and the language-switch subscriptions added, so no screenshot is needed.

[UX-REVIEWED] 3301a77

Description read

[DESCRIPTION-READ] 516fd4c49af98d25c0af5827c281f9821bdbc4a25cfc063b20bbbf367b3753c5

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 Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 3301a77c779c2fef1cbbcc17c118ea59d59f7384 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the stated problem is real, and threading the language generation into the compiled pane fixes the stale-language risk the opt-in creates.

Notes

  • Each file added to the opt-in list will have to redo the paneCopy and child-subscription work. Before the list grows, think about making the language a compiler input once, either through a hook-shaped i18nT or a shared helper. That decision belongs to a follow-up, not to this PR.
  • The new allowlist checks read one level of relative .tsx imports with regexes. A translating grandchild rendered through a non-relative path or a re-export is not checked, so the guarantee is narrower than the test names say.

[DESIGN-REVIEWED] 3301a77

Description read

[DESCRIPTION-READ] bed6ddcd57de944d021afe90fcaaf82a0bfed1ec51534f4ef1259ec02e4aa3f3

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 Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 3301a77c779c2fef1cbbcc17c118ea59d59f7384 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 3301a77

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 3301a77c779c2fef1cbbcc17c118ea59d59f7384 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 3301a77

@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 Oct 25, 2026
@Pearcekieser
Pearcekieser force-pushed the perf/react-compiler-chat-pane-notices branch from b883420 to 2500515 Compare October 25, 2026 03:01
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

issue (blocking): Compiled notices retain the previous language. Fixed in 2500515.

fixed: ChatPaneNotices builds every i18nT() and fmtDate() string in one paneCopy(useLanguageGeneration(), facts) call, so the language generation is an input of that call and a switch rebuilds every string.
src/test/ChatPaneNotices.languageSwitch.test.tsx renders the compiled component, switches to zh-CN and re-renders with identical props. It fails on b883420, where the English config notice stays, and passes on 2500515.
class guard: reactCompilerAllowlist.test.ts now fails any listed file that imports i18n/t or i18n/format without calling useLanguageGeneration().
self-added: no
mechanism: language generation passed as an argument to the one function that builds the pane's strings

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

issue (blocking): Compiled ChatPaneNotices keeps translated strings across a language switch. Fixed in 2500515.

fixed: every i18nT() and fmtDate() string in the component is built in one paneCopy(useLanguageGeneration(), facts) call. The generation argument is a reactive input, so the compiler recomputes the strings when the language changes.
src/test/ChatPaneNotices.languageSwitch.test.tsx holds every prop identical across a switch to zh-CN. It fails on b883420 and passes on 2500515.
class guard: the allowlist test fails a listed file that imports i18n/t or i18n/format without useLanguageGeneration().
self-added: no
mechanism: language generation passed as an argument to the one function that builds the pane's strings

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

Copy link
Copy Markdown
Contributor Author

thought (non-blocking): The allowlist check proves useLanguageGeneration() is called, not that every i18nT/fmtDate call runs through the generation-keyed builder.

rebutted for this head: the check catches the shape that caused the finding, a listed file that translates with no language input at all. In ChatPaneNotices every catalog read now sits in paneCopy() or the helpers it calls, so this file has no direct i18nT call to slip through.
The gap matters once more files join the list. The next P14 component PR will replace the text check with one that fails on an i18nT/fmt* call outside a function taking the generation, and add a language-switch test for that component, so the rule tightens before a second translating file is listed.
self-added: yes
mechanism: allowlist test requires useLanguageGeneration() in listed files that import i18n/t or i18n/format

@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 Oct 25, 2026
@Pearcekieser
Pearcekieser force-pushed the perf/react-compiler-chat-pane-notices branch from 2500515 to ff6706a Compare October 25, 2026 04:01
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

issue (blocking): Cached child notices stop updating on language switches. Fixed in ff6706a.

fixed: the compiled pane caches each child element while its props are unchanged, so a child that translates its own text is a memo boundary. ErrorNotice, UnrestoredTabsNotice and VoicePlaybackNotice now call useLanguageGeneration(), which re-renders them on a switch without remounting.
ChatPaneNotices.languageSwitch.test.tsx now also checks the upload-error notice's dismiss label after a switch with identical props. It fails with ErrorNotice unsubscribed and passes on ff6706a.
class guard: the allowlist test fails when a listed file imports a translating .tsx child, static or lazy, that does not call useLanguageGeneration().
self-added: no
mechanism: language subscription in each translating child the compiled pane renders

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

issue (blocking): Child notices with unchanged props keep the previous language under the compiled pane. Fixed in ff6706a.

fixed: ErrorNotice, UnrestoredTabsNotice and VoicePlaybackNotice call useLanguageGeneration(), the existing subscription for memo boundaries, so each re-renders on a switch while the compiled pane returns its cached element.
ChatPaneNotices.languageSwitch.test.tsx asserts the upload-error ErrorNotice dismiss label switches to Chinese with identical props. It fails without the subscription and passes on ff6706a.
class guard: the allowlist test fails a listed file whose translating child modules, static or lazy imports, do not subscribe. Exemptions are named with their reason in the test.
self-added: no
mechanism: language subscription in each translating child the compiled pane renders

@Pearcekieser
Pearcekieser force-pushed the perf/react-compiler-chat-pane-notices branch from ff6706a to 4aa8729 Compare October 25, 2026 04:46
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

issue (blocking): The compiled pane caches its <ErrorBoundary> element, so a visible crash card keeps the old language. Fixed in 4aa8729.

fixed: ErrorBoundary gains an optional languageGeneration prop. ChatPaneNotices hoists useLanguageGeneration() and passes it to the boundary, so the element changes on a switch and the class re-renders without resetting its error state.
src/test/ChatPaneNotices.crashCardLanguage.test.tsx makes the lazy unrestored-tabs notice throw, switches to zh-CN with identical props and expects the card heading in Chinese. It fails when the prop is omitted and passes with it.
class guard: the ErrorBoundary.tsx exemption is gone. The allowlist test now requires every <ErrorBoundary> in a listed file to pass languageGeneration.
self-added: yes
mechanism: language generation passed as a prop to the class-component boundary

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

issue (non-blocking): Compiling the pane freezes the crash fallback's language. Fixed in 4aa8729, although adjudication downgraded it.

fixed: ChatPaneNotices passes useLanguageGeneration() to ErrorBoundary through a new optional languageGeneration prop, so the boundary element changes on a switch and its card re-renders without clearing the error state.
src/test/ChatPaneNotices.crashCardLanguage.test.tsx shows the crash card, switches to zh-CN with identical props and expects the heading in Chinese. It fails without the prop.
class guard: the allowlist test requires every <ErrorBoundary> in a listed file to pass languageGeneration.
self-added: yes
mechanism: language generation passed as a prop to the class-component boundary

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

thought (non-blocking): The allowlist child check re-implements import scanning that the memo ratchet already exports.

rebutted: importedSpecifiers and resolveSpecifier live in MemoI18nSubscriptionRatchet.test.ts. Importing a test module from another test runs its describe blocks a second time, so sharing them means moving both into a non-test helper module.
The allowlist check reads one level of relative .tsx imports of each listed file, about ten lines. Moving the ratchet's helpers is a refactor of an unrelated test, so it stays out of this PR.
self-added: yes
mechanism: allowlist test scans each listed file's relative .tsx imports for translating children

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 25, 2026
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 25, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

issue (blocking): Set an explicit timeout for the lazy-boundary assertion. Fixed in 3301a77.

fixed: the first findByText in ChatPaneNotices.crashCardLanguage.test.tsx now waits up to 5000 ms, with a comment naming the chain it waits on: the lazy import() of the mocked notice resolves, the notice throws, and the boundary commits its fallback.
The assertions after the language switch stay synchronous: by then the card is mounted and the switch re-renders it in the same act().
3 shuffled runs of the three related test files, 12 of 12 each time.
self-added: yes
mechanism: named 5000 ms ceiling on the one wait that crosses a lazy boundary

@Pearcekieser
Pearcekieser force-pushed the perf/react-compiler-chat-pane-notices branch from 4aa8729 to 3301a77 Compare October 25, 2026 05:16
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 25, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

thought (non-blocking): Each listed file must redo the language work, and the allowlist checks read one level of relative .tsx imports.

accepted for the series, not this PR: making the language a compiler input once, through a hook-shaped translator or a shared helper, changes how every component calls i18nT(). That decision goes in the next P14 PR, before a second translating file joins the list.
On scope: the checks cover what a compiled file can cache, which is the elements it renders itself. A non-compiled child re-renders its own children, so a grandchild is only reachable when the child is compiled too, and then the child is a listed file and gets the same checks. The narrower case is a translating child imported through @/ or a re-export. The next PR's check will resolve those as well.
self-added: yes
mechanism: allowlist test scans each listed file's relative .tsx imports for translating children

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 25, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[operator: bolichen97] Approved at 3301a77: readiness passed, PR Readiness success, mergeable, no open blocking requests.

@bolichen97
bolichen97 merged commit 4fe3d2e into kirodotdev:main Oct 25, 2026
103 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants