SwiftUI perf tip

In lazy containers (List, LazyVStack), the view ForEach produces per element should be a *constant* number of views. An if inside the closure means 1 or 0 views, non-constant, and hits a slow path.

Wrap the condition in a VStack:

ForEach(namedFonts) { namedFont in
VStack {
if namedFont.name.count != 2 {
Text(https://namedFont.name)
}
}
}

or filter your data upfront.

Debug with: -LogForEachSlowPath YES

πŸ”— https://developer.apple.com/documentation/swiftui/foreach

Got a SwiftUI performance question like this? I'm taking them live at the WWDC26 SwiftUI Group Lab. Register now and bring yours.

πŸ“… June 10, 2026 Β· 9:00–10:00 AM PT
πŸ”— https://developer.apple.com/wwdc26/schedule/949P6QKZFA/dashboard

Activity registration - Schedule - WWDC26 - Apple Developer

Sign up for WWDC26 activities.

Apple Developer
@dnadoba Thank you for the tip, but the need for this kind of insider knowledge gets SwiftUI a bad reputation. Isn’t this something that could and should be automatically handled by the ForEach-view?