Thursday, May 12, 2016 [Tweets] [Favorites]

Beware the UIKit Visitors

Rupert H:

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

Wooji Juice:

I’ve found that setting tintColor on the view manually before adding it to the hierarchy helps a lot.

Benjamin Encz:

This means, that as soon as a _UITintColorVisitor has an original visited view (which is true after it visited its first view), the outlined code checks if the subviews array of the originalVisitedView contains the currently visited view. This check scans the full array of subviews; in cases where the originalVisitedView is 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, eax always 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.

1 Comment

[…] h/t: @jesse_squires, Michael Tsai! […]

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment