Smoother UI with AsyncDisplayKit from Facebook

Alex Manarpies
iOS App Development
2 min readDec 13, 2014

--

To many developers’ delight, Apple’s introduction of flat design with iOS 7 finally retired skeuomorphic user interface design. For third-party developers, this resulted in significantly less time fiddling with borders, rounded corners and drop shadows. And thank goodness for that! Spiffy animations are now often used to infuse apps with that extra bit of oomph. These embellishments come at additional development effort, however. And more often than not, you will need to descend into lower-level APIs to achieve pleasing results.

UIKit is the most front-facing and mature framework in the development stack. Because it was designed in an era where restricted system resources were the norm, tradeoffs were unavoidably made in its system architecture. The most poignant example in my opinion is concurrency. Don’t be fooled, UIKit remains a single-threaded API (i.e. only usable from the main queue). It’s a classic example of the 80/20 rule: it works fine 80% of the time, but rapidly turns into a suffocating stricture for the remaining 20% of the cases where concurrency is required to deliver a smooth user experience.

iOS’s main queue* draws and animates the UI at 60 frames per second, which leaves surprisingly little time left for anything else. The actual available CPU time is in the range of 10 milliseconds per frame. Take note: the OS guards this with a vengeance and will rapidly start dropping frames if you exceed this narrow time slot too egregiously.

Facebook to the rescue..?!

Facebook, of all companies, recently open-sourced its framework for asynchronous UI called “AsyncDisplayKit”. From my limited time investigating its APIs and related documentation, I’ve deduced that it allows for the decoupling of UIView (and/or CALayer) instances from the main queue by introducing a new abstraction: nodes.

Nodes are fully thread-safe and can be instantiated, laid-out and sized in the background as well as in parallel. They are supposed to behave like “drop-in replacements” for UIView and CALayer and don’t necessarily require a complete re-write.

This is extremely exciting news for me personally, as I was just researching ways to achieve background rendering of views (in addition to pre-rendering them in advance).

One of the framework’s developers gave a great introductory talk at NSLondon this year. It’s about an hour long and can be found on YouTube:

I’m keeping my eye on this one.

Credits

Header photo credits: Frank Friedrichs on Flickr

Notes

[*] queue: a multi-threading abstraction

Cross publications

This story first appeared on my blog.

--

--

Alex Manarpies
iOS App Development

Freelance #iOS developer & co-organizer of @mobel_io developer/users group #Belgium.