7

I have used diffable data source with UITableView for a while and I like it. But today I realized one issue inherent in its design. To use diffable data source, one needs to generate and apply snapshot when data changes. If the data volume is large, or more likely, the data volume is not very large but generating each data point takes a small amount of time, the accumulated time to generate snapshot would become noticeable and lead to bad user experience. I don't think the old API had this issue because delegate functions were only invoked for the items to be shown on the screen.

Since it's a new technology (it was introduced for SwiftUI, right?), I can't believe it could have so apparent limitation. But from the materials I can find on the net, I can't see how it can solve this issue. In the WWDC 2019 session 220 video, the speaker mentioned it could run on background thread in a transparent way, but I don't think that necessarily alleviate the issue in all scenarios. For example, in scenarios where data change are initiated by user interaction it's typical to process data and update UI in a synchronous way, so running on background doesn't really help.

I think I must miss something, but I can't see what it is. Any explanation will be greatly appreciated.

rayx
  • 1,329
  • 10
  • 23
  • 2
    the reason for the diffable is for the compile to knows which data has changed, by right even if you have a large data, it should only change the one which is different, unless the identifier is a local generated and it is always different. this diffable has been around with IGListKit and the performance I'm getting from using IGListkit is superb – steven lee May 03 '20 at 15:50
  • Hi @stevenlee I see your point, but unfortunately in my case when user makes some change, it's not easy to tell which items are modified/created/deleted, so what I do is to recreate a new snapshot. That takes time when using diffable data source (but not when using old API because it just creates items on demand). It seems there is no way to work around it. Thanks for mentioning IGListKit. I didn't know it. Will check it out once I get a chance. – rayx May 04 '20 at 03:25
  • What's more, even in your cases, how do you create the **first** snapshot when there are a large number of data? Don't you have to create all at once? – rayx May 04 '20 at 08:20
  • Did you measure this? If you have a lot of data to display in collection view, you may have bigger bottlenecks elsewhere. In typical situation, it's more efficient to start with a small snapshot and add more items as user is scrolling. – szotp Feb 06 '22 at 09:00
  • @szotp it doesn't necessarily have to have a lot of data. It can be, say, one hundred items, but it takes time to generate each item. The difference doesn't really matter. The key point is a) to use diffable data source one have to prepare all the items, b) but to use the old approach, you just need to prepare a small set of the items. – rayx Feb 07 '22 at 09:31

0 Answers0