Expand SwiftUI performance guidance#235
Open
jg-oai wants to merge 7 commits into
Open
Conversation
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
swiftui-performance-auditskill with a deeper review guide for diagnosing SwiftUI performance issues@Stateas view-owned state rather than an ad hoc cache@Statebelongs on the stable root view returned fromForEach, because nested child state can be recreated after offscreen content is rebuilt.taskandasyncdo not automatically move CPU-heavy synchronous work off the main actor, with@concurrentas the explicit opt-in when an async helper must hop off the caller's actorWhy
SwiftUI performance problems often come from small architectural choices that are hard to spot in isolated code snippets: unstable identity, broad observation, expensive view-body work, layout feedback loops, or async work attached to frequently recreated views. This update gives Codex more specific guidance for reviewing and improving those patterns in iOS apps.
The goal is to make the Build iOS Apps plugin more useful when developers ask Codex to audit janky scrolling, excessive re-rendering, slow layout, or performance-sensitive SwiftUI refactors.
References
ForEachrow-state guidance is grounded in SwiftUI'sForEach,LazyVStack, andStatedocumentation. Apple describesForEachas a structure that "computes views on demand," says lazy stacks create items only when needed, and notes that the "life cycle of state variables mirrors the view life cycle." The root-vs-nested state placement rule is review guidance derived from those lifecycle and lazy-creation semantics.@Observable,@State,@Bindable,@Environment, and@ObservationIgnoredis grounded in Apple's Migrating from the Observable Object protocol to the Observable macro and Discover Observation in SwiftUI. Apple describes Observation updates around "observable properties that a view's body reads."bodyevaluation, lifecycle-modifier work, layout-reader scope, stored builder closures, frequent updates, and cause-and-effect graph guidance are grounded in Apple's Understanding and improving SwiftUI performance. Apple explicitly says "Keep your view bodies fast," "avoid performing complex, long-running tasks," and "Avoid storing closures in views.".taskexecutor guidance is grounded in the Swift 6.2 release notes, which explain caller-context async execution and describe@concurrentas the way to "introduce code that runs concurrently."animation(_:body:)API documentation, which says the animation is "only used on the modifiers defined in the body."onGeometryChange, and Optimize SwiftUI performance with Instruments warns about fast-changing "geometry values or timers" in the environment. The specificPreferenceKey/anchorPreferenceframing is a review heuristic derived from that model.Binding(get:set:), because manual bindings store getter/setter closures. Action-capture narrowing and.equatable()triage are review heuristics derived from SwiftUI's identity/dependency/update model and should be treated as guidance, not direct Apple rules.Validation
git diff --check origin/main...HEAD