Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Gradients & Bad Performance when showing them #1060

Closed
5 tasks done
Rapsssito opened this issue Oct 19, 2019 · 14 comments
Closed
5 tasks done

Wrong Gradients & Bad Performance when showing them #1060

Rapsssito opened this issue Oct 19, 2019 · 14 comments
Labels

Comments

@Rapsssito
Copy link
Contributor

Rapsssito commented Oct 19, 2019

I am experiencing 1 FPS on UI when more than one animation with gradients is being reproduced on iOS. After some profiling, turns out that CGContextDrawLinearGradient is taking more than 90% of CPU time. Is there a missing swift optimization?
Furthermore, it looks like some gradients are not shown completely. I have attached a JSON that shows both errors.

Check these before submitting:

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

This issue is a:

  • Non-Crashing Bug (Visual or otherwise)

Which Version of Lottie are you using?

Lottie 3.0

What Platform are you on?

  • iOS

What Language are you in?

  • Swift

Expected Behavior

hexgood

Actual Behavior

hexbad
Note the white corner on the bottom left.

Animation JSON

Animation JSON

This might be related to this issue: #895

@Rapsssito Rapsssito changed the title Bad Performance on Gradients Wrong Gradients & Bad Performance while showing them Oct 19, 2019
@Rapsssito Rapsssito changed the title Wrong Gradients & Bad Performance while showing them Wrong Gradients & Bad Performance when showing them Oct 19, 2019
@buba447
Copy link
Collaborator

buba447 commented Nov 20, 2019

You are experiencing two issues here.

  1. The gradient is correctly displaying, its the shape that the gradient is filling that is incorrect. How is this shape being created? Is it a polygon with rounded corners or a shape layer?
  2. The gradient performance is slow, drawing gradients is expensive, but 1fps makes me think something else is wrong. Mind sharing the after effects file so I can debug when I have time?

@Rapsssito
Copy link
Contributor Author

Rapsssito commented Nov 21, 2019

@buba447, I think the issue is indeed related to the gradient generation. I have attached my AE file. It has three compositions, all look the same except for the gradient colors, but only the composition "comp 2" shows this issue.
menuMainButton.zip

@buba447
Copy link
Collaborator

buba447 commented Nov 22, 2019 via email

@Rapsssito

This comment has been minimized.

@buba447
Copy link
Collaborator

buba447 commented Nov 25, 2019

@Rapsssito You were correct! There is a bug with gradient rendering. Looking for a fix. Will update with PR.

@buba447 buba447 added the bug label Nov 25, 2019
@Rapsssito

This comment has been minimized.

@buba447
Copy link
Collaborator

buba447 commented Nov 25, 2019

I found the issue with your animation! After a lot of debugging I discovered that the gradient had two colors at the same position in after effects. If you open the gradient editor you and drag the start color you will see that there are actually three colors on top of each other:

In after effects:
Screen Shot 2019-11-25 at 10 55 12 AM

And the decoded locations:
Screen Shot 2019-11-24 at 8 16 15 PM

Core Graphics apparently bugs out if two colors occupy the same location. I could add a check to remove the erroneous color, but that check would eat up performance. (It would require a nested for loop on locations with O(N2) complexity)

Removing one of them fixes the clipping gradient issue.
As far as performance goes, gradients are expensive to render. I might try refactoring the gradient renderer to use CAGradientLayer but Im not positive if that will increase performance or not.

@Rapsssito
Copy link
Contributor Author

Rapsssito commented Nov 25, 2019

@buba447, thank you so much! After all, the issue was on my side. I apologize if this silly mistake took you a long time.

We definitely don't want O(N2) complexity with Swift... However, how is that Java outperforms Swift by that far? I can run six animations like that on solid 60 FPS on Android, but just one on 1 FPS on iOS.

@buba447
Copy link
Collaborator

buba447 commented Nov 25, 2019

Yeah the performance for this simple animation is especially bad! Far slower than it should be. Ill dig in and see what can be done.

@DariusVil
Copy link

@buba447 Any news on the issue? :)

@rolandleth
Copy link

We're having issues with this one as well, but we checked and we don't have overlapping locations. For now we had to downgrade to 2.5.3, any chance this will improve in a future release?

@dreampiggy
Copy link

dreampiggy commented Mar 9, 2020

Seems the core case is the draw with Gradient. Version 2.x seems fast on this. Should we combine the issue to #895 ??

And, any update about it ? Or can we use CAGradientLayer instead of draw gradient using CG code ? Or even more radical, use low-level Metal or GL code instead ?

Currently I've test the same image, with Lottie-iOS and Samsung's rlottie implementation on iPhone XR, the rlottie beat all the cases on animation performance.

@MobileMon
Copy link

I think the issue is happening on devices WITHOUT metal

@calda
Copy link
Member

calda commented Jul 6, 2022

I believe the issues with gradient rendering are fixed in 3.4.0 (for both the new and old rendering engine)

@calda calda closed this as completed Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants