perf(web): a provider status push no longer re-renders every provider card and model row #20851
main fromrefs/pull/20851/head·merged by juliusmarminge View on GitHubProblem#
The render audit of Settings → Providers found two expensive scenarios:
- Provider status push (only
providers[].checkedAt,usageLimits.checkedAtandversionAdvisory.checkedAtchange): 17 commits, 4283 renders. Most came from tooltips, buttons and switches in model rows (816 TooltipTrigger, 418 Tooltip, 308 Button, 114 Switch, 102 Star/Arrow icons). - Committing one field (Launch arguments blur →
settingsUpdated): 11 commits, 2321 renders, almost all in model rows.
The cause was EnvironmentProviderSettings. It subscribed to the raw providersValueAtom, and on every render it built a fresh { driver } instance for default slots plus new onUpdate / onAcceptUrlAuth / onSelect / model-preference closures for each row. Each push therefore gave every ProviderInstanceCard new props. That cascaded into ProviderModelsSection, about 50 rows each with Star, Up and Down buttons, tooltips and a switch. Only the "Checked … ago" label actually changes.
Fix#
- checkedAt-only pushes stop at the label. The panel now reads
providersIgnoringCheckedAtAtom(environmentId)(inapps/web/src/state/server.ts). When a push only restampscheckedAton a provider or itsusageLimits/versionAdvisory, that atom keeps the previous provider, and keeps the previous array if nothing else changed. This builds on the config projection already sharing unchanged nested values throughreuseUnchanged.ProviderLastCheckedsubscribes to the raw list itself and computes the latest timestamp. - settings writes share unchanged structure.
applyServerConfigProjectionnow runsreuseUnchangedonsettingsUpdated, the same treatmentproviderStatusesgot. Writing one field leavesfavorites,providerModelPreferencesand the otherproviderInstancesentries with their old identity. - Rows are a component with stable inputs. Rows render through a new
ProviderInstanceRow. It receives primitives, settings values that are now shared across pushes (explicitInstance,modelPreferences,favorites), the row'sliveProvider, and oneactionsobject ofuseStableCallbackhandlers that read settings at call time. The default slot's{ driver }is built inside the row and cached ondriver. - The models list keys on its own data.
ProviderInstanceCardderivescustomModelsandmodelsForDisplayfrominstance.config.customModelsandliveProvider.modelsinstead of the wholeinstance, andupdateCustomModelsis stable. Writing Launch arguments therefore leavesProviderModelsSectionwith identical props. - No
useMemo,useCallback,memoor"use memo"was added. Every touched file passesreactCompilerCoverage.test.ts.
Why consumers now bail out (compiled output, oxc-transform-react)#
ProviderInstanceRow (_c(124)) caches the card element on:
$[95] !== acpProjects || $[96] !== canWriteSettings || $[97] !== driverOption || ... || $[101] !== instance
|| $[104] !== liveProvider || $[107] !== projectOverride || ... || $[110] !== t10 ... $[122] !== t9
instanceis cached on$[5] driver, $[6] explicitInstance.explicitInstanceis the settings entry, shared byreuseUnchanged, orundefinedfor an untouched default slot.liveProvideris the entry fromprovidersIgnoringCheckedAtAtom, which stays the same object on a checkedAt-only push.- The closures (
t9onAcceptUrlAuth,t10onSelect, onUpdate, and the model-preference handlers) are cached onactionsandinstanceId. In the parent,actions($[46..54]) depends only onuseStableCallbackresults, so it never changes. favoriteModelsis cached on$[15] favorites, $[16] instanceId.
ProviderInstanceCard caches the Models section ($[237..251]) on customModels, modelsForDisplay, hiddenModels, favoriteModels, modelOrder, the four model callbacks and updateCustomModels. customModels and modelsForDisplay are cached on $[17] instance.driver, $[18] liveProvider?.models, $[19] storedCustomModels, and a Launch-arguments write changes none of those.
What still renders#
- Status push:
EnvironmentProviderSettingsdoes not re-render, because neither its atom nor its settings changed.ProviderLastCheckedrenders. A provider whose shown state really changed (status, version, models) re-renders its own card. - Single-field write:
EnvironmentProviderSettingsre-renders, since merged settings is a new object, and so does eachProviderInstanceRow, a cheap function that returns its cached card. Only the edited instance'sProviderInstanceCardre-renders. Its settings form and header controls update, while the Models section and the other cards stay cached.
After:
Update#
- Rebased onto main (812b700).
ProviderLastCheckedkeeps this PR's ownprovidersValueAtomsubscription and uses main'suseRelativeTimeState(lastCheckedAt)from #20819, so "Checked … ago" keeps advancing. On the old head it stayed at "just now".serverConfigProjectionkeeps both main's reconnect-snapshotreuseUnchanged(#20855) and this PR'ssettingsUpdatedone, and both of their tests. - Toggling one model no longer re-renders every model row (the follow-up from the re-measure). Rows now render through
ProviderModelRowinProviderModelsSection.tsx. It gets the model, primitive flags (isHidden,isFavorite,canMoveUp/canMoveDown,isFiltering, the two permissions) and fiveuseStableCallbackhandlers that readhiddenModels/modelOrder/favoriteModelsat call time. Compiled output (oxc-transform-react): the handler object is cached on the five stable callbacks ($[57..61]), and inside the row every element is keyed only on its own flags,modelfields and those handlers, for example the switch on$[81] model.slug, $[82] onSetHidden. On a hide/show write, only the toggled row gets a newisHidden. Rows whose group position changes, because theircanMoveUp/canMoveDownflips, re-render too. The section itself still re-renders, becausehiddenModelschanged. Not re-measured in the app yet. - Tests:
ProviderSettingsPanel.environment.test.tsx(19),ProviderModelsSection.test.ts,serverProviders.logic.test.ts,serverConfigProjection.test.tsand compiler coverage for the touched files all pass. Scoped lint and theapps/webtypecheck pass.
Tests#
apps/web/src/state/serverProviders.logic.test.ts: a checkedAt-only push returns the same array, a real change replaces only that provider, and reordering or adding providers is handled.packages/client-runtime/src/state/serverConfigProjection.test.ts:settingsUpdatedkeeps unchanged settings sections identical.ProviderSettingsPanel.environment.test.tsxwas updated for the row component and the new atom, and all 19 tests pass.- Scoped lint,
apps/webandclient-runtimetypecheck, and React Compiler coverage for the touched files all pass.
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
047600ac-94f2-4109-8488-ec820f01da64
📥 Commits
-
Reviewing files that changed from the base of the PR and between 8948f32d17009ee7502d03511e4f9000156d3161 and 24c46341be322eae76995f01e2bbd25c34bffa8d.
📒 Files selected for processing: 1
-
packages/client-runtime/src/state/server.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
📝 Walkthrough
-
The provider settings changes reuse provider data across timestamp-only updates and move provider and model row rendering into dedicated components. The client settings projection also reuses unchanged settings objects when applying updates.
Changes: Provider Settings
Layer / File(s) Summary Reuse unchanged provider snapshots
apps/web/src/state/serverProviders.logic.ts,apps/web/src/state/serverProviders.logic.test.ts,apps/web/src/state/server.tsProvider matching ignores checkedAtfields and retains prior provider objects when relevant data is unchanged. An environment atom exposes the reused provider list. Tests cover timestamp updates, status changes, reordering, and additions.Resolve provider row state and actions
apps/web/src/components/settings/ProviderSettingsPanel.tsxThe panel reads provider and project capability state, carries optional instance configuration, and uses stable callbacks for authentication, updates, persistence, and instance actions. Render provider rows and cards
apps/web/src/components/settings/ProviderSettingsPanel.tsx,apps/web/src/components/settings/ProviderInstanceCard.tsx,apps/web/src/components/settings/ProviderSettingsPanel.environment.test.tsxThe panel passes row data and actions to ProviderInstanceRow, which resolves card data and renders provider controls. Custom-model updates use a stable callback. The environment test expands provider rows to inspect rendered cards.Render provider model rows
apps/web/src/components/settings/ProviderModelsSection.tsxThe model section passes row state and stable handlers to ProviderModelRow, which renders model details and its favorite, reorder, edit, remove, and picker controls.Client Settings Projection
Layer / File(s) Summary Reuse unchanged projected settings
packages/client-runtime/src/state/serverConfigProjection.ts,packages/client-runtime/src/state/serverConfigProjection.test.ts,packages/client-runtime/src/state/server.test.tssettingsUpdatedappliesreuseUnchangedto the settings document. Tests check retained references for unchanged settings and the updated Claude launch argument.Priority: ➖ Normal
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Refactor
Suggested reviewers:
maria-rcks
Merge Risk: ⚪ Minimal · up to
24c46-
The changed test preserves both the identity check and value equality. No actionable merge-blocking issue is evident in the supplied scope.
Pre-merge checks:
3 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Description check The description clearly explains the problem, implementation, and tests, but it omits the required Scope and approval section. It also lacks the required before-and-after UI screenshots and leaves the… Add the Scope and approval section with a triaged issue or discussion link and explicit maintainer approval, or explain the applicable exemption. Add clear before-and-after screenshots for the UI changes. Replace “After: to be measured” wit… Passed checks: 3 passed-
Check name Status Explanation Title check The title clearly and concisely describes the primary performance improvement: preventing unnecessary provider card and model row re-renders during provider status pushes. Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request.
Full details: Description check
-
Explanation
The description clearly explains the problem, implementation, and tests, but it omits the required Scope and approval section. It also lacks the required before-and-after UI screenshots and leaves the measured post-change results as “to be measured.”
Resolution
Add the Scope and approval section with a triaged issue or discussion link and explicit maintainer approval, or explain the applicable exemption. Add clear before-and-after screenshots for the UI changes. Replace “After: to be measured” with the observed render measurements and test results.
-
- Fix all pre-merge checks with AI
✨ Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Re-measured in the app (seeded data, same scenario, median of 3):
Merge conflict with main. The PR conflicts in
ProviderSettingsPanel.tsxwith #20819, which replaceduseRelativeTimeTick+getRelativeTimeStateinProviderLastCheckedwithuseRelativeTimeState. For the numbers below I resolved it locally by keeping this PR's ownprovidersValueAtomsubscription and main'suseRelativeTimeState(lastCheckedAt). The PR needs that rebase before it can merge."main" is 89b42bfeb4. "This PR" is that commit plus the PR with the conflict resolved as above. The server ran without
--watch, and no window had a reconnect. Settings > Providers, 8 providers, 17 Codex model rows.scenario main this PR Refresh provider status (one providerStatusespush)3467 renders 507 hide then show one model (GPT 6.0 Luna) 2954 1654 I also measured the unrebased PR head against its merge-base b987b5785f: refresh 3474 → 514, toggle 2959 → 1659. Same result.
What still renders:
- Refresh: the settings sidebar nav (34
SidebarMenuItem),SettingsRowstate, and the 13ProviderInstanceRowfrom the scroll area. The 660TooltipTrigger/ 251Button/ 95Switchfan-out across every model row is gone. - Toggle: still about 1650. On each write
ProviderInstanceCardgets newhiddenModels/onHiddenModelsChange, so all 17 model rows re-render (Switch props:onCheckedChange×32,Star/ArrowUp/ArrowDownparent-same-props). That is half of what it was, but it is still a per-row fan-out for a one-row change. A stableonHiddenModelsChangewith per-rowhiddenwould be a follow-up.
Behaviour check (rebased build): after Refresh, "Checked just now" turned into "Checked 1m ago" a minute later, so the label still advances. Hiding GPT 6.0 Luna survived a reload (
checked=falseafter reload), and showing it again stuck. Note: on the unrebased head (and its base) the label stays at "just now" for minutes, because the compiler memoizesgetRelativeTimeStateonserverProviders. Main'suseRelativeTimeStatefrom #20819 fixes that, so the conflict resolution must keep it.- Refresh: the settings sidebar nav (34
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
Re-measured after the rebase, in the app with seeded data. Each number is the median of 3 runs of the same scenario.
"main" is 2fae0f9841. "This PR" is the PR's two commits cherry-picked onto that commit. The cherry-pick applied cleanly. The server ran without
--watchand was stopped before every checkout, and no window had a reconnect. The page was Settings > Providers.scenario main this PR Refresh provider status (one providerStatusespush)3476 renders 516 hide then show one model (GPT 6.0 Luna) 2954 680 Runs: refresh 3476/3476/3476 vs 517/516/516, toggle 2974/2954/2954 vs 700/680/680.
Last round, before the second commit, the toggle went from 2954 to 1654. With the second commit it is now 680.
What still renders:
- Refresh: the settings sidebar nav (34
SidebarMenuItem, 33SidebarMenuButton),SettingsRowstate (24), the scroll-area chrome, andProviderInstanceRow(13) re-rendered byScrollAreaViewport. No model rows render, and noSwitchorTooltipfans out. - Toggle (one direction, 332 renders): the sidebar nav again (24/22).
ProviderModelRowre-renders 15 times asparent-same-propsfromProviderModelsSection, but those renders stop at the row: noSwitch,Star, or arrow-button children re-render. Only the toggled row gets a newisHiddenand reaches itsSwitch.ProviderInstanceCardstill gets newhiddenModels/onHiddenModelsChangeprops. Memoizing the row would take out the remaining 15 row renders, but that is small.
Behaviour check: after Refresh the label read "Checked just now" and turned into "Checked 1m ago" about 60s later, so the relative time still advances. Hiding GPT 6.0 Luna survived a reload (
checked=falseafter reload). Showing it again also survived a reload (checked=true).- Refresh: the settings sidebar nav (34
juliusmarminge merged thisdb5919d
juliusmarminge closed this
Sign in to join this conversation.
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — This is a broad performance refactor spanning provider settings UI, model-row rendering, provider state identity reuse, and shared client-runtime settings projection. Although tests and structural-sharing logic are included, the scope and impact on existing runtime paths are substantial enough for human review.
Notes:
- All code in this push has already been reviewed. Approvability was decided on eligibility alone.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).