perf: move frame(maxWidth:) outside ScrollView to fix 134s LazyVStack hang (LUM-740)#24321
Merged
ashleeradka merged 1 commit intoApr 8, 2026
Conversation
…fix 134s hang (LUM-740) Move .frame(maxWidth: VSpacing.chatColumnMaxWidth) and .frame(maxWidth: .infinity) from inside the ScrollView content (MessageListContentView) to the ScrollView itself (MessageListView). These modifiers compile to _FlexFrameLayout which calls sizeThatFits on children. When placed between ScrollView and LazyVStack, new message insertions trigger initialPlacement → motionVectors → measureEstimates over ALL ForEach items, defeating laziness entirely (O(n) where each cell is complex). Moving them outside the ScrollView removes _FlexFrameLayout from the scroll content measurement path. The ScrollView is a greedy container that accepts its proposed size without measuring content, so width constraints on its frame work correctly without triggering child measurement. Padding stays inside scroll content for correct insets. Visual alignment is preserved: chatColumnMaxWidth = chatBubbleMaxWidth + 2*xl, and the internal padding of xl on each side still yields chatBubbleMaxWidth for bubble content. Co-Authored-By: ashlee@vellum.ai <ashlee@vellum.ai>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
ashleeradka
approved these changes
Apr 8, 2026
3 tasks
noanflaherty
pushed a commit
that referenced
this pull request
Apr 8, 2026
…fix 134s hang (LUM-740) (#24321) Move .frame(maxWidth: VSpacing.chatColumnMaxWidth) and .frame(maxWidth: .infinity) from inside the ScrollView content (MessageListContentView) to the ScrollView itself (MessageListView). These modifiers compile to _FlexFrameLayout which calls sizeThatFits on children. When placed between ScrollView and LazyVStack, new message insertions trigger initialPlacement → motionVectors → measureEstimates over ALL ForEach items, defeating laziness entirely (O(n) where each cell is complex). Moving them outside the ScrollView removes _FlexFrameLayout from the scroll content measurement path. The ScrollView is a greedy container that accepts its proposed size without measuring content, so width constraints on its frame work correctly without triggering child measurement. Padding stays inside scroll content for correct insets. Visual alignment is preserved: chatColumnMaxWidth = chatBubbleMaxWidth + 2*xl, and the internal padding of xl on each side still yields chatBubbleMaxWidth for bubble content. Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: ashlee@vellum.ai <ashlee@vellum.ai>
2 tasks
8 tasks
Jasonnnz
pushed a commit
that referenced
this pull request
Apr 10, 2026
Adds CI-enforced guard tests that scan Swift source files for three known LazyVStack performance anti-patterns: 1. FlexFrameLayout (.frame(maxWidth:) / .frame(maxHeight:)) in cell hierarchy 2. motionVectors transitions (.transition(.move(edge:))) in cell hierarchy 3. withAnimation in scroll handlers (motionVectors cascade) Prevents regression of fixes from PRs #24321, #24375, #24411, #24446, #24530, #24570, #24589. Part of #24613. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3 tasks
Jasonnnz
added a commit
that referenced
this pull request
Apr 10, 2026
* test: add SwiftUI performance guard tests for LazyVStack anti-patterns Adds CI-enforced guard tests that scan Swift source files for three known LazyVStack performance anti-patterns: 1. FlexFrameLayout (.frame(maxWidth:) / .frame(maxHeight:)) in cell hierarchy 2. motionVectors transitions (.transition(.move(edge:))) in cell hierarchy 3. withAnimation in scroll handlers (motionVectors cascade) Prevents regression of fixes from PRs #24321, #24375, #24411, #24446, #24530, #24570, #24589. Part of #24613. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: add missing cell files to LAZY_VSTACK_CELL_FILES and remove PR references Adds the 10 allowlisted file basenames to the cell hierarchy list so the allowlist is actually consulted. Removes historical PR numbers from the file header comment per AGENTS.md guidance. Co-Authored-By: Claude <noreply@anthropic.com> * fix: use grep -E for portable ERE alternation in FlexFrame guard BSD grep (macOS default) doesn't support \| in BRE mode. Switch to grep -E with | for alternation so the guard works for local dev too. Co-Authored-By: Claude <noreply@anthropic.com> * fix: add SubagentEventsReader to cell files and escape dots in transition grep Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Vellum Assistant <assistant@vellum.ai> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Moves
.frame(maxWidth: VSpacing.chatColumnMaxWidth)and.frame(maxWidth: .infinity)from the LazyVStack scroll content to the ScrollView container itself, eliminating_FlexFrameLayoutfrom the scroll content measurement path and fixing the biggest app hang (648+ Sentry events, 68 users).When these modifiers sit between ScrollView and LazyVStack, message insertions trigger
initialPlacement → motionVectors → sizeThatFitsthrough both_FlexFrameLayoutlayers, which callsmeasureEstimatesover every ForEach item — defeating laziness entirely (O(n), 134s hang with complex cells). Outside the ScrollView, the FlexFrame constrains the ScrollView's external frame without participating in content measurement. Same class of fix as PR #24019 and #24091 (_FlexFrameLayoutanti-pattern), but on the width axis at the scroll-content level rather than inside individual cells.Summary
.frame(maxWidth: chatColumnMaxWidth)and.frame(maxWidth: .infinity)from LazyVStack modifier chain. Padding and.environment(\.bubbleMaxWidth)remain unchanged..frame(maxWidth:)modifiers to the ScrollView, after.scrollDisabled()and before.defaultScrollAnchor().Visual alignment math is preserved:
chatColumnMaxWidth(808pt) on the ScrollView minus internal padding (2 × xl= 48pt) still yieldschatBubbleMaxWidth(760pt) for bubble content. Sibling views (banners, composer) are unaffected — they apply their own frame constraints independently.Review & Testing Checklist for Human
chatColumnMaxWidthconstrains) and narrow windows (where content should shrink below the max). Verify banner alignment (CreditsExhausted, MissingApiKey) matches the message column..frame()modifiers now sit between.scrollDisabled()and.defaultScrollAnchor()— confirm scroll anchoring is unaffected.Notes
.frame(width:)(unnecessary complexity, prevents shrinking below max),Listreplacement (wrong target — LazyVStack is correct when FlexFrame isn't in its path). See session for full analysis.Requested by: @ashleeradka