🤖 perf: skip composer height measurement for empty drafts#3540
Open
ammar-agent wants to merge 1 commit into
Open
🤖 perf: skip composer height measurement for empty drafts#3540ammar-agent wants to merge 1 commit into
ammar-agent wants to merge 1 commit into
Conversation
Collaborator
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Collaborator
Author
|
Chromatic note for baseline acceptance ( I rebuilt the Storybook for
The flagged change is a strict improvement (fixes a pre-existing empty-composer inflation bug), safe to accept as baseline. |
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.
Summary
Eliminates the forced-reflow storm that made chat/workspace switching slow: when the composer draft is empty (the common case),
useAutoResizeTextareaandfocusMessageInputno longer measurescrollHeightinside the commit phase / pre-paint rAF, letting CSS size the empty textarea instead.Background
A CDP CPU profile of a live session (30s, repeated chat switches, ~49k-node transcript) showed switches blocking the renderer main thread for 0.6–3.4s each. The hottest application frame by far (2.18s self time, 14% of busy time; up to 991ms inside a single switch) was
useAutoResizeTextarea's layout effect, called fromcommitLayoutEffectsduring the sync render triggered by the switch click.The cost is not JS: the effect writes
height = "auto"then readsscrollHeight, which forces a synchronous layout of the entire freshly-mounted (fully dirty) document before first paint.focusMessageInputinChatInputrepeats the same dance in a pre-paint rAF on every switch.Implementation
useAutoResizeTextarea: fast path forvalue === ""— clear any stale inline height (matching the existing send-path convention ofstyle.height = ""+ "let CSS min-height take over"), record state, and skip measurement entirely. NoscrollHeightread, no reflow. The first keystroke afterwards takes the existing grow-only path (measures once on a clean tree, noautoreset).focusMessageInput(ChatInput): skip theauto/scrollHeightresize dance when the composer is empty; it fires right after a workspace switch while the new transcript is still dirty.VimTextArea/AskUserQuestionToolCalltextareas:rows={1}so the natural (un-measured) empty height stays one line — textareas default torows=2. With the consumers' existingmin-h-*clamps, the rendered empty height is unchanged (verified live: empty composer renders at exactly its CSSmin-height, same as before).Non-empty drafts keep the existing measure-on-mount behavior.
Validation
rows=1, andoffsetHeightexactly equals its CSSmin-height(pixel-identical to the previous measured state).scrollHeightreads and zero style writes; clearing to empty resets the inline height; first keystroke after the unmeasured empty state grows without theautoreset.Risks
Low-moderate, scoped to composer sizing. The empty state is now CSS-governed; if a consumer styled the empty composer expecting an inline px height (none found — both consumers have
min-hclamps that already dominated), its empty height could shift by a couple px. Typing, draft-restore, deletion/shrink, and max-height capping paths are unchanged and covered by existing tests.Generated with
mux• Model:anthropic:claude-fable-5• Thinking:high• Cost:$2.11