UITintColorVisitor causes exponentially worsening performance when adding subviews

Number:rdar://26227380 Date Originated:11-May-2016 09:31 PM
Status:Closed Resolved:
Product:iOS SDK Product Version:9.3.1
Classification:Crash/Hang/Data Loss Reproducible:Always
When adding subviews to a view that obtains its tint color from the window or a parent view performance gets exponentially worse the more subviews you add. When adding 6000 subviews execution takes over 10 minutes in the following method chain:

In _postMovedFromSuperview, _UIViewVisitorRecursivelyEntertainDescendingVisitors, _UITintColorVisitor.visitView, checking NSArray.containsObject.

It appears UIKit is visiting all sibling views to set their tintColor when only a single sibling is added.

Here is a really simple sample project demonstrating the problem. If you tap the Custom Tint Color button it will take several minutes to run. If you tap the No Tint Color button the subviews are added so quickly you might miss it. The identical code is running in both cases, the only difference is whether the application UIWindow has a tintColor set.

Steps to Reproduce:
Set window tintColor to a non-default color
Create a subview class
Add 6000 subviews to the parent view
Observe exponentially decreasing performance as UITintColorVisitor continuously re-scans the growing array.

Expected Results:
Performance should not get exponentially worse with more subviews

Actual Results:
Performance gets exponentially worse

iOS 9.3, Xcode 7.3.1

A temporary workaround is to explicitly set the tintColor on all subviews but that defeats the purpose of tintColor's inheritance system. This is a duplicate of rdar://25934331


Solved in iOS 10.3

16-Mar-2017 04:22 PM

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!