Serious performance issues in -[UICollectionView performBatchUpdates:completion:]
| Originator: | marco | ||
| Number: | rdar://31423807 | Date Originated: | 04/04/2017 |
| Status: | Open | Resolved: | |
| Product: | iOS + SDK | Product Version: | 10.2 |
| Classification: | Reproducible: | Always |
Area: UIKit Summary: UICollectionView seems to have serious performance issues when using a ‘complex’ layout with many sections and and many supplementary/decoration views in each section. UICollectionView blocks the main thread when calling -[UICollectionView performBatchUpdates:completion:] and performing changes. I've attached a screenshot of time profiler in Instruments. It looks as though most of the time is spent in UICollectionView’s internal classes, UICollectionViewData in particular, accessing NSDictionaries, probably using NSIndexPath as the key by looking at how much time is spent is -[NSIndexPath hash] and -[NSIndexPath isEqual:]. The issue is only present when using supplementary views. When only showing items, -[UICollectionView performBatchUpdates:completion:] is very performant. I'm excluding a problem in my own layout, given that I'm making good use of caches, never recomputing attributes that have already been computed. Moreover, Instruments clearly shows performance issues in UIKit's internal classes. Steps to Reproduce: 1. Run the example project and start scrolling the app horizontally 2. As you scroll, new items will be added calling -[UICollectionView performBatchUpdates:completion:] 3. Notice how the scroll is very laggy. This is because -[UICollectionView performBatchUpdates:completion:] blocks the main thread. 4. Now, stop the app and comment out the code in CollectionViewLayout.m from line 83 to line 95, which removes supplementary views. 5. As you scroll, new items will be added calling -[UICollectionView performBatchUpdates:completion:] 6. Notice how the scroll is now very performant. Expected Results: -[UICollectionView performBatchUpdates:completion:] should be very performant, regardless of whether the UICollectionView is making use of supplementary/decoration views. Actual Results: -[UICollectionView performBatchUpdates:completion:] is very slow when supplementary/decoration views are being used. Version: iOS 10.2 Configuration: iOS simulator, iPhone 6S Attachments: 'UICollectionView performance.png' and 'RDAR - CollectionViewBatchUpdates.zip' were successfully uploaded. https://www.dropbox.com/sh/uguxlfqxo6nybny/AACoVVRGzZlecrur29PguQESa?dl=0
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!