Beware the UIKit Visitors
My discovery for the day is iOS has an O(n^2) cost to add a subview so never have too many subviews on a view or performance goes to shit
I’ve found that setting tintColor on the view manually before adding it to the hierarchy helps a lot.
This means, that as soon as a
_UITintColorVisitorhas an original visited view (which is true after it visited its first view), the outlined code checks if thesubviewsarray of theoriginalVisitedViewcontains the currently visited view. This check scans the full array of subviews; in cases where theoriginalVisitedViewis our root view, the cost of this operation grows linearly with the amount of added subviews.[…]
Once we know the memory address offset we can create breakpoints in lldb based on addresses in Hopper.
[…]
With this approach I identified that with the current sample code,
eaxalways refers to the root view. This means we are iterating over all subviews of the root view, N times for each subview that is added.
Update (2016-05-14): See also: Hacker News.