Xcode 13 UICollectionViewDiffableDataSource Performance Issue

Originator:magicpop
Number:rdar://FB9649428 Date Originated:Sep 23, 2021 at 4:59 PM –
Status:Open Resolved:
Product:UIKit Product Version:15.0
Classification:Incorrect/Unexpected Behavior Reproducible:Always
 
When building a project with Xcode 13 that uses UICollectionViewDiffableDataSource and NSDiffableDataSourceSectionSnapshot, the performance of the creation of the initial snapshot has worsened dramatically compared to when built with Xcode 12.5. The issues appears to be related to Hashable and having the UICollectionViewDiffableDataSource store the models as their ItemIdentifierType. As you add properties to your model, the performance continues to get worse and worse. If you only store an identifier for the model in the data source, it does not have the performance issues.

I’ve created a sample project that shows this behavior where you store the model vs the identifier. You can then run the Time Profiler and see the difference in the amount of time it takes for the loadInitialItems() to complete. I’m attaching instruments profiles for Xcode 12.5 and Xcode 13.

Open the project in Xcode 12.5 and run profile.
Select the Time Profiler and hit record.
Tap on the models tab and then ids tab.
Look at the time performance logged for the models tab and then ids
You shouldn’t see a major difference in the time for loadInitialItems() which is called from the viewDidLoad() of the controller.

Open the project in Xcode 13 and run profile.
Select the Time Profiler and hit record.
Tap on the models tab and then ids tab.
Look at the time performance logged for the models tab and then ids.
You will see a major difference in the time for loadInitialItems() which is called from the viewDidLoad() of the controller for the models tab vs the IDs tab.
Add another property to the Item struct in models tab such as let moreText: String 
Run the Time Profiler again and notice the time for the models tab has gotten worse.

The time difference I am seeing are as follows:

Xcode 12:
Model: 94.00 ms
ID: 96.00 ms  

Xcode 13:
Model: 1.07 s
ID: 282.00 ms  

Xcode 13 adding one property to models:
Model: 1.21 s

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!