<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/diagnosing-foreach-performance-issues-in-swiftui-lazy-containers-m4lorccsm" -->

---
title: Diagnosing ForEach performance issues in SwiftUI lazy...
description: Explains how to enable SwiftUI's -LogForEachSlowPath launch argument to detect ForEach patterns inside List and lazy stacks that force SwiftUI to evaluate...
canonical: https://daily.dev/posts/diagnosing-foreach-performance-issues-in-swiftui-lazy-containers-m4lorccsm
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Diagnosing ForEach performance issues in SwiftUI lazy containers | daily.dev
og:description: Explains how to enable SwiftUI's -LogForEachSlowPath launch argument to detect ForEach patterns inside List and lazy stacks that force SwiftUI to evaluate...
og:url: https://daily.dev/posts/diagnosing-foreach-performance-issues-in-swiftui-lazy-containers-m4lorccsm
og:image: https://api.daily.dev/og/posts/m4LorCcsM.png
og:image:alt: Diagnosing ForEach performance issues in SwiftUI lazy containers
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Diagnosing ForEach performance issues in SwiftUI lazy containers

**[Nil Coalescing](https://daily.dev/sources/nilcoalescing)** · 4 min read · 0 upvotes · 0 comments

## Summary

Explains how to enable SwiftUI's -LogForEachSlowPath launch argument to detect ForEach patterns inside List and lazy stacks that force SwiftUI to evaluate offscreen content early. Covers two common triggers: conditionally filtering elements inside the ForEach closure (fix: filter the collection before passing it to ForEach) and conditionally adding an extra view per element (fix: wrap content in a VStack to give a constant view count). Includes code examples and a link to a book chapter with further guidance on list performance.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://nilcoalescing.com/blog/DiagnosingForEachPerformanceIssuesInSwiftUILazyContainers>

## Questions this post answers

### Why does SwiftUI show 'Unable to determine number of views per element' in the debug console?

This diagnostic appears when a ForEach inside a List or lazy stack produces a variable number of views per element, forcing SwiftUI to evaluate the content closure for every element upfront, including offscreen ones. Common causes are an if condition inside the closure that skips rendering some elements, or a conditional view added alongside a constant one. Enable it via the -LogForEachSlowPath YES launch argument in Xcode.

_Debugging list slowdowns in SwiftUI is easier with clear technical writeups like this saved on daily.dev._

### How do I fix a SwiftUI ForEach that filters elements with an if condition inside a List?

Filter the collection before passing it to ForEach instead of using an if condition inside the closure. Placing a VStack around the condition, as the diagnostic message suggests, would retain an empty row for excluded elements rather than removing them. Filtering upfront gives one row per element, letting SwiftUI determine row identifiers without evaluating every content closure.

_Developers optimizing SwiftUI lists can track patterns like this on daily.dev when refining their own code._

### How do I keep a ForEach on the fast path when each element conditionally shows an extra view, like a date header?

Wrap the entire per-element content in a VStack so the lazy container sees exactly one subview per element, while the inner VStack can still vary its child count. Without this wrapping, lazy stacks must resolve the conditional view count to determine indices for later subviews, keeping offscreen views alive longer. Grouping content this way removes the slow-path diagnostic entirely.

_daily.dev surfaces practical SwiftUI performance fixes like this for developers tuning list rendering._

## Similar posts on daily.dev

- [SwiftUI Performance: Find Redraws in Xcode Instruments](https://daily.dev/posts/swiftui-performance-find-redraws-in-xcode-instruments-ybsyckv3q) · SwiftLee · 1 upvotes · 0 comments
- [The Secret Behind SwiftUI's Type-Checking Speedup](https://daily.dev/posts/the-secret-behind-swiftui-s-type-checking-speedup-hqbxf0ack) · Fatbobman · 0 upvotes · 0 comments

---

Tags: [#performance](https://daily.dev/tags/performance), [#ios](https://daily.dev/tags/ios), [#swift](https://daily.dev/tags/swift), [#swiftui](https://daily.dev/tags/swiftui)

[View this post on daily.dev](https://daily.dev/posts/diagnosing-foreach-performance-issues-in-swiftui-lazy-containers-m4lorccsm)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Diagnosing ForEach performance issues in SwiftUI lazy containers","url":"https://daily.dev/posts/diagnosing-foreach-performance-issues-in-swiftui-lazy-containers-m4lorccsm","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/diagnosing-foreach-performance-issues-in-swiftui-lazy-containers-m4lorccsm"},"datePublished":"2026-09-15T20:39:54.037Z","dateModified":"2026-09-15T20:40:47.015Z","description":"Explains how to enable SwiftUI's -LogForEachSlowPath launch argument to detect ForEach patterns inside List and lazy stacks that force SwiftUI to evaluate...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/846e60ce52909e29818143192a2e8368?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/846e60ce52909e29818143192a2e8368?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Nil Coalescing","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Nil Coalescing","logo":"https://media.daily.dev/image/upload/s--rcEu6sag--/f_auto,q_auto/v1785654899/logos/nilcoalescing?_a=BAMAMicg0","url":"https://daily.dev/sources/nilcoalescing"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/diagnosing-foreach-performance-issues-in-swiftui-lazy-containers-m4lorccsm","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"performance,ios,swift,swiftui","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Nil Coalescing","item":"https://daily.dev/sources/nilcoalescing"},{"@type":"ListItem","position":3,"name":"Diagnosing ForEach performance issues in SwiftUI lazy containers"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/diagnosing-foreach-performance-issues-in-swiftui-lazy-containers-m4lorccsm#faq","mainEntity":[{"@type":"Question","name":"Why does SwiftUI show 'Unable to determine number of views per element' in the debug console?","acceptedAnswer":{"@type":"Answer","text":"This diagnostic appears when a ForEach inside a List or lazy stack produces a variable number of views per element, forcing SwiftUI to evaluate the content closure for every element upfront, including offscreen ones. Common causes are an if condition inside the closure that skips rendering some elements, or a conditional view added alongside a constant one. Enable it via the -LogForEachSlowPath YES launch argument in Xcode. Debugging list slowdowns in SwiftUI is easier with clear technical writeups like this saved on daily.dev."}},{"@type":"Question","name":"How do I fix a SwiftUI ForEach that filters elements with an if condition inside a List?","acceptedAnswer":{"@type":"Answer","text":"Filter the collection before passing it to ForEach instead of using an if condition inside the closure. Placing a VStack around the condition, as the diagnostic message suggests, would retain an empty row for excluded elements rather than removing them. Filtering upfront gives one row per element, letting SwiftUI determine row identifiers without evaluating every content closure. Developers optimizing SwiftUI lists can track patterns like this on daily.dev when refining their own code."}},{"@type":"Question","name":"How do I keep a ForEach on the fast path when each element conditionally shows an extra view, like a date header?","acceptedAnswer":{"@type":"Answer","text":"Wrap the entire per-element content in a VStack so the lazy container sees exactly one subview per element, while the inner VStack can still vary its child count. Without this wrapping, lazy stacks must resolve the conditional view count to determine indices for later subviews, keeping offscreen views alive longer. Grouping content this way removes the slow-path diagnostic entirely. daily.dev surfaces practical SwiftUI performance fixes like this for developers tuning list rendering."}}]}
```

