Optimize chat composer render hot path#2600
Open
cursor[bot] wants to merge 7 commits intomainfrom
Open
Conversation
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>
This reverts commit b355e12.
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Contributor
ApprovabilityVerdict: 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
onCommandKeyDown/onPasteprop churn onComposerPromptEditor.Why
react-doctorflaggedChatComposerfor an O(n*m) provider lookup and a cascadinguseEffectstate sync in the composer menu. React Scan on the/modelcomposer interaction also showedComposerPromptEditorre-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-doctorweb diagnostics: 763 -> 761 total;ChatComposerperf/state findings: 6 -> 4. Thejs-index-mapsprovider lookup warning and menu-highlightno-cascading-set-statewarning are gone./modelinteraction:ComposerPromptEditorchange samples changed fromprops:["onCommandKeyDown","onPaste"]toprops:[]; measured editor duration improved from 16.8ms before to 7.1ms after in the captured run.UI Changes
No visual UI changes expected.
Checklist
Note
Optimize
ChatComposerrender hot path with memoized lookups and stable callbacksMapkeyed byinstanceId, used forlockedContinuationGroupKey,selectedInstanceId, andselectedProviderEntry.useStableCallbackto giveonComposerCommandKeyandonComposerPastestable function identities across renders without stale closure issues.composerHighlightedItemIdandcomposerHighlightedSearchKeyon menu open; the active item is now derived on-demand viaresolveComposerMenuActiveItemId.composerHighlightedSearchKeyon each nudge.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.tsxand primarily performance-oriented.Overview
Optimizes
ChatComposerrender/interaction performance by replacing repeated provider-instance array scans with a memoizedMapkeyed byinstanceId, 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
useStableCallbackand applies it toonComposerCommandKeyandonComposerPaste(and wraps image-attach logic inuseCallback) to reduce callback identity churn passed intoComposerPromptEditor.Reviewed by Cursor Bugbot for commit da1c215. Bugbot is set up for automated code reviews on this repo. Configure here.