Asserting Lottie 4.0 for iOS. A brand new rendering engine with vital… | by Cal Stephens | The Airbnb Tech Weblog | Dec, 2022

Asserting Lottie 4.0 for iOS. A brand new rendering engine with vital… | by Cal Stephens | The Airbnb Tech Weblog | Dec, 2022
Asserting Lottie 4.0 for iOS. A brand new rendering engine with vital… | by Cal Stephens | The Airbnb Tech Weblog | Dec, 2022

A brand new rendering engine with vital efficiency enhancements powered by Core Animation

By: Cal Stephens

Lottie is Airbnb’s cross-platform, open source library for rendering vector movement graphics. We use Lottie extensively at Airbnb, and it additionally powers animations in hundreds of different apps all through the trade.

Instance Lottie animations included in Airbnb’s iOS app

At present we’re releasing Lottie 4.0 for iOS. This main new launch brings vital efficiency enhancements to all Lottie animations, with a model new rendering engine powered by Core Animation.

Utilizing Lottie at scale for a few years, we’ve discovered so much about its efficiency traits in real-world use instances. We discovered that it was comparatively widespread for Lottie animations to drop frames in a few of our extra complicated screens. To know why, we first have to try how Lottie beforehand rendered animations.

Earlier variations of Lottie performed animations on the app’s essential thread, successfully utilizing a CADisplayLink. As soon as per body, Lottie would execute code on the principle thread to advance the progress of the animation and re-render its content material. This meant that animations would eat 5–20%+ of the CPU whereas taking part in, leaving fewer CPU cycles obtainable for the remainder of the app:

Taking part in an animation with Lottie 3.5.0, utilizing the unique essential thread rendering engine

This additionally meant that animations wouldn’t replace when the principle thread was busy. This might trigger animations to drop frames or freeze totally, which leads to a poor person expertise:

Lottie animations dropping frames when the principle thread is overloaded

These points are inherent limitations of utilizing a main-thread-bound rendering structure.

On iOS, essentially the most performant and power-efficient technique to play animations is by utilizing Core Animation. This technique framework renders animations out-of-process with GPU {hardware} acceleration. Animation playback is managed by a separate system course of referred to as the “render server”. This implies Core Animation-powered animations don’t contribute to the CPU utilization of the app course of itself, and might proceed even when its essential thread is blocked or busy.

All through 2022, we’ve been engaged on a brand new rendering engine implementation for Lottie constructed on prime of Core Animation. For every of the layers within the animation JSON file, the brand new engine builds a CALayer and applies CAAnimations with keyframes for the layer’s animated properties. Lottie passes these animation keyframes off to Core Animation, which takes care of really rendering them on-screen and updating the animation every body.

This new engine eliminates the CPU overhead from taking part in a Lottie animation, and successfully ensures that Lottie animations will animate easily at 60 or 120 fps whatever the app’s CPU load.

Taking part in an animation with Lottie 4.0, utilizing the brand new Core Animation rendering engine

Since animations rendered by the brand new engine don’t execute any code on the app’s essential thread, apps now have extra sources obtainable for different performance. That is particularly helpful when working duties with excessive CPU load. For instance, the Airbnb app shows a Lottie animation when beginning up for the primary time. We ran an experiment right here and located that switching to the brand new rendering engine reduces our app’s complete launch time, whereas additionally bettering the frame-rate and UX of the startup animation.

We first introduced the Core Animation rendering engine in Lottie 3.4.0 earlier this yr, behind an opt-in characteristic flag. We’ve been utilizing the brand new engine by default for all Lottie animations within the Airbnb app for over six months, and have been exhausting at work fixing points reported by early-adopters locally.

Beginning in at the moment’s Lottie 4.0 launch for iOS, the Core Animation rendering engine is enabled by default for all apps utilizing Lottie, with no further work or migration required by app builders. This can be a main milestone that we’ve been working in direction of for a very long time, and we hope it helps elevate the bar for animation high quality and efficiency even greater all through the trade!

Lottie 4.0 for iOS additionally consists of a number of vital enhancements contributed by members of the group:

  • Help for dotLottie animation files, that are a lot smaller in measurement than commonplace JSON recordsdata
  • A brand new animation decoding implementation that’s ~2x quicker than the earlier Codable-based implementation

You may study extra about Lottie, and our dedication to open supply, in earlier posts we’ve printed:

All in favour of working at Airbnb? Take a look at these open roles:

Staff Software Engineer, Wishlists

Staff Software Engineer, Guests & Hosts

Many due to Eric Horacek for first proposing this undertaking and reviewing 100+ pull requests over the previous yr. Additionally due to Brandon Withrow, the unique writer of Lottie, plus the many other contributors who’ve helped out through the years.