Diffable datasource performance issues with > 20K rows
G

1

7

I run into performance issues with the diffable data source when having a larger data set, around 22,000 items. I am surprised that applying the snapshot takes so much time when animation is ON. See the code section:

let shouldAnimate = tableView.numberOfSections != 0
apply(snapshot as NSDiffableDataSourceSnapshot<String, NSManagedObjectID>, animatingDifferences: shouldAnimate)

Note: there is a good resource here by Jesse Squires:

My questions is, am I missing something or diffable data source cannot handle this any faster given that applying a snapshot is an O(n) operation?

Turning off animation, same as reloadData, would somewhat help.

The sample code was setup based on this article by the awesome SwiftLee.

enter image description here

Please see the sample project here.

Sample video here.

Update (September 2nd, 2021): A good Twitter discussion here.

Sidenote: The sample app can be improved by not setting the fetchBatchSize since the request is used with a NSFetchedResultsController. See link.

Gentility answered 25/8, 2021 at 11:33 Comment(0)
N
3

In iOS 15 we now have Apply SnapShot Using ReloadData.

It's a lot faster than apply snapshot if you are replacing data and dont care about animations

Nunes answered 30/8, 2022 at 9:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.