DevPrep

All topics › SwiftUI

How do you make a long list fast: List, LazyVStack and stable ids?

Senior PRO

The gist

A long list's speed comes down to three things: how many rows are actually created, how expensive each row's body is, and how stable the identifiers are. A VStack inside a ScrollView creates all rows at once — with hundreds of items that is already noticeable. LazyVStack and List create rows as they approach the visible area. On iOS 16+ List is built on top of UICollectionView and reuses cells; LazyVStack creates rows lazily but does not reuse cells that way, so for very long feeds with complex rows List is usually more memory-efficient.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store