Repository navigation
fix(ios): Debug builds nearly overflow the main-thread stack in the chat composer - #165472
Conversation
Debug builds keep every nested `some View` temporary on the stack, and the composer is one chain of nested getters. Measured in a Debug simulator build at the composer attachment menu, main used 959,744 bytes of main-thread stack; an iPhone's main thread has 1,032,192. Two closure-backed section views split the chain and bring the same measurement to 299,808 bytes.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 5:25 AM ET / 09:25 UTC. ClawSweeper reviewWhat this changesThe shared native chat composer evaluates its content and editor in separate SwiftUI view bodies to reduce stack use in Debug builds. Merge readiness✅ Ready for maintainer review The PR remains useful: current main still evaluates the composer subtrees inline, and no canonical replacement was found. The narrow patch has no actionable correctness findings and includes real simulator measurements supporting the stack reduction. Priority: P2 Review scores
Verification
How this fits togetherThe shared native chat composer turns session state, draft text, and attachment controls into the input area used by Apple clients. This change splits rendering evaluation while preserving the existing input bindings and action callbacks. flowchart TD
A[Session and draft state] --> B[Native chat composer]
B --> C[Composer content view body]
C --> D[Editor view body]
C --> E[Attachment and toolbar controls]
D --> F[Rendered chat input]
E --> F
Before mergeNone. Agent review detailsSecurityNone. PR surfaceOther +10. Total +10 across 1 file. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep rendering evaluation bounded through the two lightweight view bodies while retaining the composer's existing state and input owners. Do we have a high-confidence way to reproduce the issue? No exact current-main device crash was reproduced in this review. The contributor provides a concrete Debug rendering measurement, while the actual device crash required additional wrappers on a separate local branch. Is this the best way to solve the issue? Yes: separating evaluation into two SwiftUI bodies is a focused repair that preserves the existing view contents, modifier placement, bindings, and state ownership. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 10080eaf91bc. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
chessing234
left a comment
There was a problem hiding this comment.
Reviewed commit 3f83cf82f7256aea6f6ab3e956e916a5c59183ea.
Inspected the SwiftUI composer extraction, bindings, and modifiers. No actionable correctness issue found.
Validation: static source review only; runtime tests were not run. This review makes no assertion that CI or platform tests pass.
|
Reviewed exact head The two internal closure-backed bodies defer construction while keeping existing state, draft bindings, focus, actions and modifier order in their original owners. Production +12/-2 (net +10) supplies those two construction boundaries; tests are unchanged. Full owner/caller/sibling source review found no introduced P0–P2 defect. Fresh AutoReview is scoped-clean; its sandbox lacked the owner files, so that pass is contextual and supplements the independent full-source review. I inspected the actual native CI run37289222143: Xcode27 Debug, integration merge The reported numeric stack reduction, 2287-test local suite with its unrelated compiler workaround, and physical-device recovery on a different branch remain author-reported. I do not claim an independently measured stack improvement or exact-head physical-device recovery. Direct SwiftUI construction-contract evidence plus the observed native Debug rendering/input flow supports this bounded preparation; required native gates and clean mergeability remain prerequisites to landing. The latest completed ClawSweeper review has no actionable findings or Rank-up moves. It is older than twelve hours, so @clawsweeper re-review. A refreshed publisher result is requested; no approving GitHub review or automatic merge is being submitted. |
|
Merged via squash.
|
…aw#165472) Debug builds keep every nested `some View` temporary on the stack, and the composer is one chain of nested getters. Measured in a Debug simulator build at the composer attachment menu, main used 959,744 bytes of main-thread stack; an iPhone's main thread has 1,032,192. Two closure-backed section views split the chain and bring the same measurement to 299,808 bytes. Co-authored-by: Marvinthebored <[email protected]>
What Problem This Solves
Fixes: a Debug build of the iOS app is within a few percent of overflowing the main-thread stack when the chat composer first draws, so one more view layer in the composer makes the app crash at launch on a real device.
User Impact
User impact: no change for released builds. Developers and testers running Debug builds on a physical iPhone get about 660 KB of stack headroom back in the composer, instead of a launch crash the next time a wrapper or modifier is added there.
Why This Change Was Made
Unoptimized builds keep every nested
some Viewtemporary on the stack, and the composer is one chain of nested getters evaluated in a single body. A small closure-backed view evaluates two parts of that chain (the styled composer content and the editor) in their own bodies, which splits the chain. Layout, modifiers and observation are otherwise unchanged; the wrapped subtrees are the same views in the same places.Evidence
Measured on
mainbbaabd6ced1in a Debug simulator build, with lldb stopped at the composer's attachment menu getter during the first composer draw, summing frame sizes on the main thread:mainmainis: on a local branch that added two thin wrapper views to the composer, the same measurement read 993,120 bytes and a Debug build on a physical iPhone crashed on its first frame with a main-thread stack overflow (SIGSEGV in the stack guard) while the Swift runtime resolved opaque view types under the attachment menu getter. With the same section view applied there (where it also replaced the two wrappers) the measurement was 249,280 bytes and the app launched. That branch is not part of this PR.mainc1b9f4ec91e; it also merges cleanly withc2e6410cd6c, not retested there): 2287 tests in 194 suites passed. SwiftFormat lint clean on the changed file.Bindingsetter inChatSessionSidebarPages.swift, a file this PR does not change (the same crash occurs on unmodifiedmain). Local runs used an uncommitted one-line workaround in that file to build; CI builds the unmodified tree.AI-assisted (Claude).