Skip to content

Optimize chat composer render hot path#2600

Open
cursor[bot] wants to merge 7 commits intomainfrom
cursor/react-performance-scan-6a79
Open

Optimize chat composer render hot path#2600
cursor[bot] wants to merge 7 commits intomainfrom
cursor/react-performance-scan-6a79

Conversation

@cursor
Copy link
Copy Markdown
Contributor

@cursor cursor Bot commented May 8, 2026

What Changed

  • Removed the effect-driven composer menu highlight sync and derive the active menu item during render instead.
  • Indexed provider instance entries once so composer model/provider resolution avoids repeated linear lookups.
  • Stabilized composer editor event handlers so React Scan no longer reports onCommandKeyDown / onPaste prop churn on ComposerPromptEditor.

Why

react-doctor flagged ChatComposer for an O(n*m) provider lookup and a cascading useEffect state sync in the composer menu. React Scan on the /model composer interaction also showed ComposerPromptEditor re-rendering with callback prop changes. This keeps the same behavior while reducing follow-up state work and callback churn in the hot composer path.

Measurements:

  • react-doctor web diagnostics: 763 -> 761 total; ChatComposer perf/state findings: 6 -> 4. The js-index-maps provider lookup warning and menu-highlight no-cascading-set-state warning are gone.
  • React Scan /model interaction: ComposerPromptEditor change samples changed from props:["onCommandKeyDown","onPaste"] to props:[]; measured editor duration improved from 16.8ms before to 7.1ms after in the captured run.

UI Changes

No visual UI changes expected.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes
Open in Web View Automation 

Note

Optimize ChatComposer render hot path with memoized lookups and stable callbacks

  • Replaces linear array scans for provider instance lookups with a memoized Map keyed by instanceId, used for lockedContinuationGroupKey, selectedInstanceId, and selectedProviderEntry.
  • Introduces useStableCallback to give onComposerCommandKey and onComposerPaste stable function identities across renders without stale closure issues.
  • Removes the effect that synchronized composerHighlightedItemId and composerHighlightedSearchKey on menu open; the active item is now derived on-demand via resolveComposerMenuActiveItemId.
  • Arrow key nudge now advances from the resolver-derived active item and persists composerHighlightedSearchKey on each nudge.
  • Behavioral Change: highlighted item state is no longer eagerly synced via an effect; menus derive active selection lazily instead.

Macroscope summarized da1c215.


Note

Medium Risk
Touches core chat composer input/keyboard navigation and provider/model resolution; behavior should be equivalent but subtle menu-highlight or selection regressions are possible. Changes are localized to ChatComposer.tsx and primarily performance-oriented.

Overview
Optimizes ChatComposer render/interaction performance by replacing repeated provider-instance array scans with a memoized Map keyed by instanceId, used for locked continuation group resolution and selected instance/provider entry lookups.

Removes the effect that synchronized menu highlight state and instead derives the active command-menu item during render via resolveComposerMenuActiveItemId; arrow-key nudging now advances from this derived active item and keeps the highlight search key in sync.

Introduces useStableCallback and applies it to onComposerCommandKey and onComposerPaste (and wraps image-attach logic in useCallback) to reduce callback identity churn passed into ComposerPromptEditor.

Reviewed by Cursor Bugbot for commit da1c215. Bugbot is set up for automated code reviews on this repo. Configure here.

cursoragent and others added 7 commits May 8, 2026 16:10
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels May 8, 2026
@juliusmarminge juliusmarminge marked this pull request as ready for review May 8, 2026 16:55
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented May 8, 2026

Approvability

Verdict: Needs human review

Performance optimization that removes a useEffect responsible for synchronizing composer menu highlight state. While the intent is optimization, the structural changes to state management timing warrant verification that highlight behavior remains correct.

You can customize Macroscope's approvability policy. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant