Diffable datasource performance issues with > 20K rows

1k Views Asked by At

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.

1

There are 1 best solutions below

0
On

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