I have a List with an unfiltered data set of 16.000 items. Initial loading works perfectly, but filtering = making changes to list’s items is extremely slow and takes more than 20 seconds.
The issue is described here:
If you take a look at Instruments it tells you that almost all CPU time is spent in CollectionChanges.formChanges(). This method calculates the changes (insertions, removals) to a list to be able to animate them.
So the above link recommends to set an id on List to tell SwiftUI that every change represents a new list. It then should not try to animate the changes - and therefore not call CollectionChanges.formChanges() - but draw the List immediately.
But above trick doesn't seem to work anymore (iOS 13.6 and Xcode 11.6), SwiftUI still calculates the changes and animates them.
So is there any way to tell SwiftUI to not animate changes to a List?
Here's the sample code from above's link:
struct ContentView: View {
@State var items = Array(1...1600)
var body: some View {
VStack {
Button("Shuffle") {
self.items.shuffle()
}
List(items, id: \.self) {
Text("Item \($0)")
}
.id(UUID())
}
}
}
(Side note: The workaround suggested here, SwiftUI Bug - List changes lock UI - (OLD TITLE: SwiftUI CoreData fetch is very slow), to show an empty list for 100 ms also doesn't work.)