airbnb / lottie-ios

An iOS library to natively render After Effects vector animations
http://airbnb.io/lottie/
Apache License 2.0
25.76k stars 3.75k forks source link

CoreAnimation rendering engine hangs up the app when used with a specific file #2002

Closed mennahmostafa closed 1 year ago

mennahmostafa commented 1 year ago

When using the attached animation file with Lottie V4.x using the default configuration (as in the below code snippet), the app freezes and the main thread does not respond to any events.

private var animationView: LottieAnimationView = .init(name: "Wave")

But when specifying the engine as MainThread (as in the below code snippet), the app doesn't freeze:

    private var animationView: LottieAnimationView = .init(name: "Wave", configuration: LottieConfiguration(renderingEngine: .mainThread))

Note: this issue was not present before we upgraded to Lottie4.x

Which Version of Lottie are you using?

Lottie 4.1.3

Expected Behavior

Displaying the animation using the CoreAnimation rendering engine should not block the main thread.

Actual Behavior

Displaying the animation using the CoreAnimation rendering engine blocks the main thread.

Animation JSON

Wave.json.txt

calda commented 1 year ago

There seems to be an issue in Core Animation itself causing this animation to render with poor performance.

When I test the animation I see the main thread itself has low CPU usage (e.g. 0% when playing the animation), but the app's render performance is poor / laggy. The render performance is also sluggish when using the Main Thread rendering engine, but not quite as bad. This suggests there's an issue in the Core Animation render server causing this performance problem, and probably not something we can fix in Lottie.

Since there's a decent workaround (use the Main Thread rendering engine) that mitigates some of the performance issues, I'm going to close this issue for now. It seems like an Apple framework issue that we wouldn't be able to work around in the Lottie library.

mennahmostafa commented 1 year ago

Alright, thanks @calda! Hope this helps others.