CodexBloom - Programming Q&A Platform

Trouble with SwiftUI's List Performance When Using Large Data Sets in iOS 17

👀 Views: 13 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-18
swiftui performance optimization swift

I'm testing a new approach and I tried several approaches but none seem to work. I've been struggling with this for a few days now and could really use some help... I'm a bit lost with I am currently working on a SwiftUI application where I need to display a large data set (around 10,000 items) in a `List`. While the `List` works fine for smaller datasets, I am experiencing important performance optimization when trying to load the larger set. The UI becomes unresponsive, and I see stuttering when scrolling. I've tried using `@State` to manage the data, but it doesn't seem to improve the situation. Here's the relevant code snippet: ```swift struct ContentView: View { @State private var items: [String] = [] var body: some View { List(items, id: \.self) { item in Text(item) } .onAppear { loadItems() } } private func loadItems() { // Simulate loading 10,000 items items = (1...10000).map { "Item \($0)" } } } ``` I've also experimented with using `LazyVStack` and `ForEach`, but the performance optimization continue. When I run Instruments, I notice high CPU usage, which seems to be related to the `List` rendering process. Is there a recommended best practice for efficiently displaying such a large number of items in SwiftUI? Any suggestions on how to improve performance would be greatly appreciated! I recently upgraded to Swift 3.10. Is there a better approach? I'm working on a service that needs to handle this. Thanks for your help in advance! My team is using Swift for this mobile app. This is part of a larger desktop app I'm building. Any feedback is welcome!