Lottie-ios: High memory and CPU overhead

Created on 3 Feb 2021  路  3Comments  路  Source: airbnb/lottie-ios

Check these before submitting:

  • [x] The issue doesn't involve an Unsupported Feature
  • [] This issue isn't related to another open issue

This issue is a:

  • [x] Non-Crashing Bug (Visual or otherwise)
  • [] Crashing Bug
  • [x] Feature Request
  • [] Regression (Something that once worked, but doesn't work anymore)

Which Version of Lottie are you using?

Lottie 3.2.0

What Platform are you on?

  • [] MacOS
  • [x] iOS 14.4 (likely does not matter)

What Language are you in?

  • [x] Swift
  • [] Objective-C

Expected Behavior


Low memory and CPU overhead.

Actual Behavior


High memory and CPU overhead

iPhone 11 Pro Max gets physically hot while sitting on a screen with a stock Lottie animation

Memory overhead is ~150-200MB at worst on top of the existing, base memory otherwise
CPU overhead is ~60-80% at worst on top of the existing, base CPU otherwise (doing nothing else in background)

The result is excessively low frame rates when scrolling, in our case, a page view controller.

Screen Shot 2021-02-03 at 3 54 46 PM

Code Example

final class OnboardingPageBlahBlahBlah: OnboardingPage
{
    @IBOutlet private var animationContainer: UIView!

    private let animationView = AnimationView( animation: Animation.named( "43885-laptop-working" ) )

    override func viewDidLoad()
    {
        super.viewDidLoad()

        animationView.frame = animationContainer.bounds
        animationContainer.addSubview( animationView )
        animationView.loopMode = .loop
        animationView.backgroundBehavior = .pauseAndRestore
    }

    override func viewDidAppear( _ animated: Bool )
    {
        super.viewDidAppear( animated )

        // Workaround bug in Lottie...dispatch to next run loop to ensure animation has loaded
        DispatchQueue.main.async
        {
            self.animationView.play()
        }
    }
}

Animation JSON


https://lottiefiles.com/43885-laptop-working

All 3 comments

@buba447 As I understand this is an open-source project without full time maintenance, a proper fix for performance could be time intensive and not possible in the short term.

Is there a suitable workaround? Maybe a version I can downgrade to while remaining compatible with Swift 5 (and preferably SPM)?

If not, is there anything I can do to help out?

Thanks Brandon!

We also discovered this issue. A temp fix is to use the last known OBJ-C lottie version. in 2.x.x but the downside is that it dosnt support so many AE effects

IIRC buba mentioned the issue had to do with swift structs consuming more memory/CPU than he expected, and that a rewrite of several sections would be necessary.

IMO this library is so useful big companies should sponsor @buba447 to work on it full time, or Apple should should add native support lol

Was this page helpful?
0 / 5 - 0 ratings