Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

async makeViews method #120

Open
staguer opened this issue Apr 6, 2017 · 2 comments
Open

async makeViews method #120

staguer opened this issue Apr 6, 2017 · 2 comments

Comments

@staguer
Copy link
Contributor

staguer commented Apr 6, 2017

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.

@nicksnyder
Copy link
Collaborator

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).

@staguer
Copy link
Contributor Author

staguer commented Apr 7, 2017

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants