Xcode 16 - List Lazy loading broken

In Xcode 16 and Xcode 16.1 beta 2 the lazy loading of list does not work properly. Tested on physical device with iOS 17.

Below is minimal code to reproduce this issue: You can see in the debug console how many child views are initialized based on the print statement.

import SwiftUI

@main
struct TestDemoApp: App {
    let data = Array(1...1000)
    var body: some Scene {
        WindowGroup {
            List(data, id: \.self) { item in
                SomeView(item: item)
            }
        }
    }
}

struct SomeView: View {
    static var count = 0
    let item: Int
    init(item: Int){
        self.item = item
        Self.count += 1
        print(Self.count)
    }
    var body: some View{
        Text(String(item))
            .frame(height: 100)
    }
}

When the view is shown the List creates all child views at once as shown in the console output:

It does not loads only first 13 out of 1000 as it does in older xcode 15.2: As the List is quite often used component in Swiftui Apps, the apps will be slow, because all the data are loaded and the main thread will be stuck until all child views are loaded.

FB15356563 (Xcode 16 breaks SwiftUI List lazy loading feature)

I can also see this issue. I've spent more than 2 days to figure out why my code in Xcode 16 + Swift 5 + iOS 17.7 works really slow comparing to Xcode 15 + Swift 5 + iOS 17.7 on physical device and simulator as well. I can see that Xcode 16 + Swift 5 + iOS 17.7 loads all the rows of my data completely instead of on demand as it is in Xcode 16 + Swift 5 + iOS 17.7

I'm experiencing the same bug also in my project.

I can still see this issue in Xcode 16.1 so I have to use Xcode 15.4 on macOS 15.0.1 (24A348).

@Apple please fix it to use the latest Xcode features.

Hello I don't know if I arrive to late to the party but be aware that Apple has introduce a new settings that does some optimisation for previews but potentially breaks List lazy loading in debug.

Basically since Xcode 16, Apple introduced a new execution engine for Previews with 30% improvements between edits and rendered previews. More technically, it does type erasing by wrapping your SwiftUI Views to AnyViews. Only in DEBUG. So this also comes at the cost of making your code less performant at runtime (besides breaking some List lazy loading optimization and others). But the other annoying thing is that you might get completely different behaviour between RELEASE/DEBUG where some code could be working fine in DEBUG but not being re-rendered when it should, and thus completely buggy in RELEASE... To turn this off, you can set this in your project (Build Settings for your target, Add User-Defined Setting)

SWIFT_ENABLE_OPAQUE_TYPE_ERASURE=NO

Don't know if this will help but at least you now have some more information on what could explain your issues.

We are experincing the same type of issue, unfortuentely changing "SWIFT_ENABLE_OPAQUE_TYPE_ERASURE=NO" did not fix it for us.

If anyone else have any idea, please let me know.

Xcode 16 - List Lazy loading broken
 
 
Q