koral-- / android-gif-drawable

Views and Drawable for displaying animated GIFs on Android
Other
9.54k stars 1.78k forks source link

CPU Usage when having more GifImageView's #817

Closed Madeleaan closed 1 year ago

Madeleaan commented 1 year ago

I have an app that overlays multiple images onto each other with FrameLayout. This also includes 6 GifImageViews. However, when i go to that activity, the cpu usage in the profile spikes to 60% and stays around that level afterwards. This only happens on my old tablet (Samsung Galaxy Tab 4), which is the only device that will be running this app. On my phone (Xiaomi Redmi Note 9 Pro), it has no problem.

Having all the gifs paused on the view creation will still result in a noticeable lag. Is there a way to optimize it, or is it just the old CPU struggling to render so many moving things at once?

koral-- commented 1 year ago

Could you create and share a reproducer project?

Madeleaan commented 1 year ago

The project is available at https://github.com/Madeleaan/Noustea. The gifs are currently paused programatically in src/main/java/madeleaan/noustea/ui/viewport/ViewportFragment.kt

koral-- commented 1 year ago

Sorry for the delay. I don't see any field of improvement inside the library. The only idea I have is to use opaque GIFs where possible. If there is always the same color in the background, you can embed it into the GIFs. Alpha channel can be omitted then and there will be less bytes to process.