The problem
A SwiftUI list with fifty rows feels instant. The same code with fifty thousand rows takes a second to open, hitches while scrolling, or redraws every visible row when one value changes. The cause is rarely the container itself. It is almost always identity, dependencies or work done inside a row, and each of those has a specific fix you can measure.
How List and lazy stacks load rows
Both containers are lazy, but in different ways, and the differences explain most of the advice below.
List is backed by UIKit. Fatbobman notes in List or LazyVStack that it wraps UICollectionView from iOS 16 on. Apple’s Demystify SwiftUI performance session explains the part that matters: List and Table gather the identifiers of every row up front, then create row content on demand for the visible region plus a buffer. Row bodies are lazy. Identifiers are eager. That is why cheap IDs matter even when only a dozen rows are on screen.
LazyVStack inside a ScrollView is pure SwiftUI. The WWDC26 session Dive into lazy stacks and scrolling with SwiftUI walks through its model. It lays out subviews only until the visible rect is full, and estimates the height of everything off screen from the views it has measured. It addresses subviews by index. It may prefetch views before they appear, spreading body evaluation across frames. Views that scroll away are kept for a while, then deleted along with their @State. And because only part of the data is in memory, it checks only visible views for changes instead of diffing the whole content.
Those estimates explain a trade-off Fatbobman measured. A LazyVStack that jumps far, for example a scroll to the bottom of thousands of rows, has to evaluate bodies to replace estimates, which can show blank space or stall. List doesn’t track the full content height and handles big jumps better. LazyVStack, on the other hand, gives you full control over layout, transitions and the iOS 17 and 18 scroll APIs.
Choosing a container
Apple’s guidance in Creating performant scrollable stacks is to start with a plain VStack and switch to a lazy stack only when profiling shows a real gain, because eager stacks know every subview’s size and lay out reliably. For anything with more than a screen or two of repeated rows, you’ll end up lazy.
| Need | Use |
|---|---|
| System rows, swipe actions, edit mode, selection, sidebar style | List |
| Tens of thousands of uniform rows, jumping to either end | List |
| Custom card layouts, grids, scroll transitions | ScrollView + LazyVStack or LazyVGrid |
| Precise programmatic scrolling and visibility callbacks | ScrollView + LazyVStack with ScrollPosition (iOS 18+) |
| Under a few dozen rows | ScrollView + VStack, or List for system styling |
Community benchmarks disagree on which container is faster in general, and they test different things. Pick by features first, then measure your own data on a device.
Identity: the part that decides everything
Every row needs an identifier that is stable and unique. Stable means it doesn’t change while the item exists. Unique means no two rows share it.
import Foundation
struct Message: Identifiable, Hashable, Sendable {
let id: UUID
var sender: String
var preview: String
var avatarURL: URL
var isUnread: Bool
}
The mistakes look harmless:
- Indices as IDs.
ForEach(items.indices, id: \.self)ties identity to position. Insert at the top and every row’s identity shifts, so SwiftUI animates the wrong rows and keeps state attached to the wrong data. - Fresh IDs on each read.
var id: UUID { UUID() }hands SwiftUI a new identity on every evaluation, so every update looks like all new rows. id: \.selfon large values. It works, but every identity check hashes the whole value. A storedidis cheaper and survives edits to other fields.
A constant number of views per element
The WWDC23 session gives the rule: the row count of a List is the number of elements times the number of views each element produces, and that per-element count should be constant. Three patterns break it.
A bare if inside ForEach produces zero or one view per element, so SwiftUI has to build each row to learn whether it exists. AnyView hides the count entirely. Filtering inline in body is linear over the collection on every update. The WWDC26 session adds that the same applies to lazy stacks, which address views by index and must keep earlier views alive when a row’s subview count can change.
Filter in the model and give ForEach exactly the data it should show:
import SwiftUI
@MainActor
@Observable
final class InboxModel {
var messages: [Message] = [] {
didSet { rebuildUnread() }
}
private(set) var unread: [Message] = []
private func rebuildUnread() {
unread = messages.filter(\.isUnread)
}
}
struct UnreadList: View {
let model: InboxModel
var body: some View {
List(model.unread) { message in
MessageRow(sender: message.sender, preview: message.preview, avatarURL: message.avatarURL)
}
}
}
With SwiftData, filter with a #Predicate on @Query instead, as the WWDC26 session shows. An if/else that always yields one view is fine. A bare if without else is the one to avoid.
The .id modifier inside a List
Fatbobman traced a one-second delay opening a 40,000-row List to a single modifier in Demystifying SwiftUI List Responsiveness. Each row had .id(item.objectID) so the list could scroll to it with ScrollViewReader. That .id pulled the rows out of the ForEach optimization, and List instantiated all 40,000 of them on entry. Removing it brought the count back to the dozen or so visible rows. His follow-up notes that LazyVStack and LazyVGrid don’t have this problem.
The other common misuse is .id(UUID()) or .id(refreshToken) on the whole list to force a reload. That changes the list’s identity, throws away every row’s state, resets the scroll position and rebuilds from scratch. If data changed, change the data. If you need to scroll to an item, use ScrollPosition on a lazy stack:
import SwiftUI
struct ThreadView: View {
let messages: [Message]
@State private var position = ScrollPosition(idType: Message.ID.self)
var body: some View {
ScrollView {
LazyVStack(alignment: .leading, spacing: 12) {
ForEach(messages) { message in
MessageRow(sender: message.sender, preview: message.preview, avatarURL: message.avatarURL)
}
}
.scrollTargetLayout()
}
.scrollPosition($position)
.toolbar {
Button("Latest") {
if let last = messages.last {
withAnimation { position.scrollTo(id: last.id) }
}
}
}
}
}
ScrollPosition and scrollTo(id:anchor:) require iOS 18. The WWDC26 session notes that scrolling to an ID is fastest when each ForEach element resolves to exactly one subview, because the stack can find the target without building views. If your deployment target is iOS 17, ScrollViewReader with IDs coming from ForEach itself (no extra .id) is the fallback.
Keep rows cheap
Once identity is right, the remaining cost lives in row bodies.
No expensive work in body. In the WWDC25 Instruments session, each row created a NumberFormatter and a MeasurementFormatter on every body evaluation. Moving formatting into the model, reusing formatters and caching the strings removed the long updates. String interpolation, bundle lookups and allocations in body add up the same way.
Narrow dependencies. Pass a row the values it displays instead of the whole model. MessageRow above takes three values, so changing isUnread on a message doesn’t re-run its body. The WWDC25 session shows the opposite case: a helper that read a whole favorites array made every row depend on that array.
Set up in init, not onAppear. The WWDC26 session explains that prefetching can prepare a view before it appears, and that work started in onAppear for every row gets thrown away. Keep init cheap, but anything a row computes from its inputs belongs there or in the model. onAppear is still the right tool for pagination, on a trailing loading row.
State that survives scrolling lives outside the row. Lazy stacks delete off-screen rows and their @State. Expansion flags, draft text and selection go in the model or in a parent passed down by binding.
Don’t change layout after a row appears. The WWDC26 session shows rows that measured themselves with onGeometryChange and then resized, which pushed content and misaligned scroll targets. Give images and placeholders a fixed frame, and use a custom Layout when sizing depends on measurement.
Images
Decoding a 4000-pixel photo to show it in a 56-point avatar wastes memory and main-thread time. UIImage.byPreparingThumbnail(ofSize:) (iOS 15+) decodes at the target size off the main thread, as Apple’s documentation describes. Cache the result so a row that scrolls back doesn’t decode again.
import SwiftUI
import UIKit
actor ThumbnailCache {
static let shared = ThumbnailCache()
private var images: [URL: UIImage] = [:]
func thumbnail(for url: URL, pixelSize: CGSize) async throws -> UIImage? {
if let cached = images[url] { return cached }
let (data, _) = try await URLSession.shared.data(from: url)
guard let full = UIImage(data: data) else { return nil }
let thumbnail = await full.byPreparingThumbnail(ofSize: pixelSize)
images[url] = thumbnail
return thumbnail
}
}
struct MessageRow: View {
let sender: String
let preview: String
let avatarURL: URL
var body: some View {
HStack(spacing: 12) {
Avatar(url: avatarURL)
VStack(alignment: .leading) {
Text(sender).font(.headline)
Text(preview).font(.subheadline).foregroundStyle(.secondary).lineLimit(2)
}
}
}
}
struct Avatar: View {
let url: URL
@State private var image: UIImage?
@State private var failed = false
@Environment(\.displayScale) private var displayScale
var body: some View {
Group {
if let image {
Image(uiImage: image).resizable().scaledToFill()
} else {
Image(systemName: failed ? "person.crop.circle.badge.exclamationmark" : "person.crop.circle")
.foregroundStyle(.secondary)
}
}
.frame(width: 44, height: 44)
.clipShape(.circle)
.accessibilityHidden(true)
.task(id: url) {
let side = 44 * displayScale
do {
image = try await ThumbnailCache.shared.thumbnail(for: url, pixelSize: CGSize(width: side, height: side))
failed = image == nil
} catch {
failed = true
}
}
}
}
The frame is fixed, so loading never changes the row’s height. The if/else always produces one view. .task(id:) cancels when the row goes away and restarts if the URL changes. A production cache also needs a size limit, which this sketch leaves out.
Measure with Instruments
Profile on a device. Apple’s scrollable stacks article says never to profile performance in the Simulator.
- In Xcode choose Product > Profile, then pick the SwiftUI template.
- Record while you open the list, scroll fast, jump to the end and change a row’s data.
- Read the SwiftUI track. Apple’s performance article defines the lanes: Update Groups shows when SwiftUI is working, and Long View Body Updates marks bodies over 500 microseconds in orange and over 1,000 microseconds in red. Start with the red ones.
- Control-click a long update, choose Set Inspection Range and Zoom, and read the Time Profiler call tree for that range.
- For many short updates, open the cause-and-effect graph on an update group. It shows which state change or observable property invalidated which view bodies.
- Check the Hitches track against what you saw on screen.
The WWDC25 session adds a caution about the first second after launch: long updates while the initial hierarchy builds don’t always cause hitches. Focus on what happens during scrolling and interaction.
Record again after every fix. The cause-and-effect graph shows one changing property per edge, so removing one cause can reveal the next.
Checklist
Identifiablemodels with a stored, stableid. No indices, no computedUUID().ForEachgets pre-filtered data. No bareif, noAnyViewin rows.- No
.idon rows inside aList. No.id(UUID())to force refreshes. - Rows receive values, not whole models.
- No formatters, filtering or decoding in
body. - Images decoded at display size, cached, in fixed frames.
- State that must survive scrolling lives above the row.
navigationDestinationsits outside the lazy container.- Every change confirmed with the SwiftUI instrument on a real device.
Sources and further reading
- Creating performant scrollable stacks Apple Developer Documentation
- Understanding and improving SwiftUI performance Apple Developer Documentation
- Demystify SwiftUI performance (WWDC23) Apple
- Optimize SwiftUI performance with Instruments (WWDC25) Apple
- Dive into lazy stacks and scrolling with SwiftUI (WWDC26) Apple
- List or LazyVStack: Choosing the Right Lazy Container in SwiftUI Fatbobman (Xu Yang)
- Demystifying SwiftUI List Responsiveness: Best Practices for Large Datasets Fatbobman (Xu Yang)
- prepareThumbnail(of:completionHandler:) Apple Developer Documentation