Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(web): a provider status push no longer re-renders every provider card and model row #20851

Mergedjuliusmarmingemerged 4 commits intomain fromrefs/pull/20851/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Problem

The render audit of Settings → Providers found two expensive scenarios:

  • Provider status push (only providers[].checkedAt, usageLimits.checkedAt and versionAdvisory.checkedAt change): 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) (in apps/web/src/state/server.ts). When a push only restamps checkedAt on a provider or its usageLimits / 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 through reuseUnchanged. ProviderLastChecked subscribes to the raw list itself and computes the latest timestamp.
  • settings writes share unchanged structure. applyServerConfigProjection now runs reuseUnchanged on settingsUpdated, the same treatment providerStatuses got. Writing one field leaves favorites, providerModelPreferences and the other providerInstances entries 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's liveProvider, and one actions object of useStableCallback handlers that read settings at call time. The default slot's { driver } is built inside the row and cached on driver.
  • The models list keys on its own data. ProviderInstanceCard derives customModels and modelsForDisplay from instance.config.customModels and liveProvider.models instead of the whole instance, and updateCustomModels is stable. Writing Launch arguments therefore leaves ProviderModelsSection with identical props.
  • No useMemo, useCallback, memo or "use memo" was added. Every touched file passes reactCompilerCoverage.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
  • instance is cached on $[5] driver, $[6] explicitInstance. explicitInstance is the settings entry, shared by reuseUnchanged, or undefined for an untouched default slot.
  • liveProvider is the entry from providersIgnoringCheckedAtAtom, which stays the same object on a checkedAt-only push.
  • The closures (t9 onAcceptUrlAuth, t10 onSelect, onUpdate, and the model-preference handlers) are cached on actions and instanceId. In the parent, actions ($[46..54]) depends only on useStableCallback results, so it never changes.
  • favoriteModels is 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: EnvironmentProviderSettings does not re-render, because neither its atom nor its settings changed. ProviderLastChecked renders. A provider whose shown state really changed (status, version, models) re-renders its own card.
  • Single-field write: EnvironmentProviderSettings re-renders, since merged settings is a new object, and so does each ProviderInstanceRow, a cheap function that returns its cached card. Only the edited instance's ProviderInstanceCard re-renders. Its settings form and header controls update, while the Models section and the other cards stay cached.

After:

Update

  • Rebased onto main (812b700). ProviderLastChecked keeps this PR's own providersValueAtom subscription and uses main's useRelativeTimeState(lastCheckedAt) from #20819, so "Checked … ago" keeps advancing. On the old head it stayed at "just now". serverConfigProjection keeps both main's reconnect-snapshot reuseUnchanged (#20855) and this PR's settingsUpdated one, 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 ProviderModelRow in ProviderModelsSection.tsx. It gets the model, primitive flags (isHidden, isFavorite, canMoveUp/canMoveDown, isFiltering, the two permissions) and five useStableCallback handlers that read hiddenModels/modelOrder/favoriteModels at 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, model fields and those handlers, for example the switch on $[81] model.slug, $[82] onSetHidden. On a hide/show write, only the toggled row gets a new isHidden. Rows whose group position changes, because their canMoveUp/canMoveDown flips, re-render too. The section itself still re-renders, because hiddenModels changed. Not re-measured in the app yet.
  • Tests: ProviderSettingsPanel.environment.test.tsx (19), ProviderModelsSection.test.ts, serverProviders.logic.test.ts, serverConfigProjection.test.ts and compiler coverage for the touched files all pass. Scoped lint and the apps/web typecheck 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: settingsUpdated keeps unchanged settings sections identical.
  • ProviderSettingsPanel.environment.test.tsx was updated for the row component and the new atom, and all 19 tests pass.
  • Scoped lint, apps/web and client-runtime typecheck, 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

    2. juliusmarminge added labelsmacroscope-review

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      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).
    4. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ⚠️ The latest CI run did not produce a thread transfer result for 24c4634.

      This comment will update automatically after the next completed run.

    5. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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.ts
      Provider matching ignores checkedAt fields 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.tsx
      The 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.tsx
      The 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.tsx
      The 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.ts
      settingsUpdated applies reuseUnchanged to 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: Passed 3 · Failed 1
      Failed Failed checks: 1 warning
      Check nameStatusExplanationResolution
      Description checkWarningThe 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 Passed checks: 3 passed
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the primary performance improvement: preventing unnecessary provider card and model row re-renders during provider status pushes.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck 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
      Comment `@coderabbitai help` to get the list of available commands.
    6. Re-measured in the app (seeded data, same scenario, median of 3):

      Merge conflict with main. The PR conflicts in ProviderSettingsPanel.tsx with #20819, which replaced useRelativeTimeTick + getRelativeTimeState in ProviderLastChecked with useRelativeTimeState. For the numbers below I resolved it locally by keeping this PR's own providersValueAtom subscription and main's useRelativeTimeState(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.

      scenariomainthis PR
      Refresh provider status (one providerStatuses push)3467 renders507
      hide then show one model (GPT 6.0 Luna)29541654

      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), SettingsRow state, and the 13 ProviderInstanceRow from the scroll area. The 660 TooltipTrigger / 251 Button / 95 Switch fan-out across every model row is gone.
      • Toggle: still about 1650. On each write ProviderInstanceCard gets new hiddenModels / onHiddenModelsChange, so all 17 model rows re-render (Switch props:onCheckedChange ×32, Star/ArrowUp/ArrowDown parent-same-props). That is half of what it was, but it is still a per-row fan-out for a one-row change. A stable onHiddenModelsChange with per-row hidden would 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=false after 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 memoizes getRelativeTimeState on serverProviders. Main's useRelativeTimeState from #20819 fixes that, so the conflict resolution must keep it.

    7. 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 --watch and was stopped before every checkout, and no window had a reconnect. The page was Settings > Providers.

      scenariomainthis PR
      Refresh provider status (one providerStatuses push)3476 renders516
      hide then show one model (GPT 6.0 Luna)2954680

      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, 33 SidebarMenuButton), SettingsRow state (24), the scroll-area chrome, and ProviderInstanceRow (13) re-rendered by ScrollAreaViewport. No model rows render, and no Switch or Tooltip fans out.
      • Toggle (one direction, 332 renders): the sidebar nav again (24/22). ProviderModelRow re-renders 15 times as parent-same-props from ProviderModelsSection, but those renders stop at the row: no Switch, Star, or arrow-button children re-render. Only the toggled row gets a new isHidden and reaches its Switch. ProviderInstanceCard still gets new hiddenModels / onHiddenModelsChange props. 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=false after reload). Showing it again also survived a reload (checked=true).

    8. juliusmarminge merged thisdb5919d

    9. juliusmarminge closed this

Sign in to join this conversation.