LayoutKit
LayoutKit copied to clipboard
async makeViews method
When an arrangement's UIViews are expensive to create and configure, makeViews
can take more time than is available between frames.
Current idea is to add an asyncMakeViews
method that would walk the arrangement tree in batches, checking CADisplayLink
for whether to pause the walk to let a frame render.
I am curious if you have have a concrete example of this actually being a problem (what does the view look like and how big is it?).
You will need to be careful about synchronization. For example, if another makeViews pass starts for a new layout, you will want to cancel the async makeViews for the previous layout if it is still happening.
Also think about how this will impact animation (I don't think it is possible to do both).
The size is about a screen-full or more and includes expensive views such as UITextView. According to profiling, much of the time is spent in makeViews, either constructing UIView instances or running config blocks. One workaround has been to async dispatch the config blocks to run a bit later, and to stagger them so that they don't get bunched up again. This cut the framedrops by half, which matched the approximate breakdown between the time spent on UIView instantiation and on config blocks. The only thing we haven't done was to add stopwatch/print calls around the makeViews calls to confirm that those times correspond closely to the number of frames dropped.
Good points about synchronization, cancellation, and animations.