Excessive ressource usage with NavigationLinks in LazyVStack

When a large number of NavigationLinks is within a LazyVStack (or LazyVGrid), ressource usage gets higher (and stays high) the further a user scrolls down.

A simple example to reproduce this:

NavigationStack {
    ScrollView {
        LazyVStack {
            ForEach(0..<5000) { number in
                NavigationLink(value: number) {
                    Text("Number \(number)")
                }
            }
        }
    }
    .navigationDestination(for: Int.self) { number in
        Text("Details for number \(number)")
    }
}

List does not exhibit this behavior but is not suitable for my use case.

@leoklaus Thanks for flagging this, I looked into this further and replacing the NavigationLink with a Button in an attempt to programmatically manage the navigation stack and path also has the same unexpected behavior.

I would suggest you file a bug report via Feedback Assistant and please post the Feedback ID here so I can follow up with the issue. Thanks

Excessive ressource usage with NavigationLinks in LazyVStack
 
 
Q