r/SwiftUI
•
u/romit5587
•
18h ago
A checklist I use when a SwiftUI List or ScrollView stutters
Most SwiftUI scroll jank I've debugged came from a short list of causes, not from SwiftUI being slow. Here's the order I check them in. Curious what others would add.
- Unstable identity. `ForEach(items, id: \.self)` on values that aren't unique, or ids created inside the view (`UUID()` in `body`), make SwiftUI treat rows as new on every update. Use a stable id from your model.
- Work inside `body`. Date formatters, sorting, filtering or image decoding in `body` run on every re-render. Move them into the model or cache the result.
- Observing too much. With `@Observable`, a view re-renders for the properties it reads. If every row reads half of a big shared model, one change can invalidate far more rows than you expect. Give each row only what it needs.
- Conditional modifiers that swap view types. An `if` that wraps a row in different modifiers changes its structural identity and resets its state. Prefer value-based modifiers, like `.opacity(isHidden ? 0 : 1)`.
- Images. Full-size images decoded on the main thread will drop frames. Downsample to the size you actually display.
Before changing anything, I profile on a real device with a release build, using Instruments (the SwiftUI template plus Time Profiler). `Self._printChanges()` in `body` is also handy for seeing why a view re-rendered. Debug builds and the simulator can point you at the wrong problem.
What's the most surprising cause of scroll jank you've run into?