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

Glide gif CPU consumption #1604

Closed
alexzaitsev opened this issue Nov 22, 2016 · 7 comments
Closed

Glide gif CPU consumption #1604

alexzaitsev opened this issue Nov 22, 2016 · 7 comments

Comments

@alexzaitsev
Copy link

Hello.
I have an adapter with gifs (important: it's inherited from BaseAdapter, not RecyclerView.Adapter). It contains gifs loaded from original url.
Tested using Samsung A5 2016 - Android 6.0.1 - 2134 and with a total of 3 sent GIFs, only 2 were in focus and the app the CPU usage was at 50 - 65%. When all 3 GIF were in view, CPU consumption did not change.
Tested also with 15+ GIFs and CPU was at 99%.

In ideal world I would use RecyclerView.Adapter and RecyclerView.Adapter.onViewRecycled method to clear ImageView. But it's impossible due to current implementation.

What could you advice me to prevent excess CPU consumption?

@alexzaitsev
Copy link
Author

Hello @TWiStErRob! Excuse me for upping this but I really need to understand it. Do you have some spare time to answer me?

@sjudd
Copy link
Collaborator

sjudd commented Dec 7, 2016

At the moment gif frame decoding simply is CPU intensive. Using transformations that upscale can dramatically increase CPU usage, but even just decoding frames with no downsampling or transformations is expensive.

The Android framework has a library called framesequence that will decode animated GIFs and WebP images. It's relatively simply to integrate it with Glide. If you do write the integration and would like to contribute it, I'd welcome the pull request.

One option without relying on an external library would be to cache each frame of GIFs in our disk cache. Doing so requires passing previously the previous frame into our GifDecoder each time we start a new frame load so that we can initialize the decoder with the previous frame. If you'd like to work on that I'd be happy to try to point you in the right direction and would welcome a pull request for that as well.

@alexzaitsev
Copy link
Author

@sjudd Thank you for your answer. I understand these issues. But it's not that I asked :(

@sjudd
Copy link
Collaborator

sjudd commented Dec 8, 2016

You asked "What could you advice me to prevent excess CPU consumption?". Is that the question you're referring to, or did you mean to ask another?

If you did mean to ask that one, I believe I addressed it, but feel free to ask for clarifications.

@sjudd sjudd closed this as completed Dec 8, 2016
@radixdev
Copy link

@sjudd

The "framesequence" library doesn't come included as a library in the system directory. Did you mean that it instead should be added as a jni lib to glide itself? I'd be willing to do it, but wanted to clarify.

@sjudd
Copy link
Collaborator

sjudd commented Dec 19, 2016

@radixdev Yes, it would be another integration library (similar to the okhttp, volley and other libraries in integrations/).

Here's a link to the library I'm referring to. I'm not sure if it's released just as code, or if it's actually part of a publicly released library somewhere, I'll try and look in to it: https://android.googlesource.com/platform/frameworks/ex/+/android-7.1.1_r6/framesequence/.

@radixdev
Copy link

That's what I found too. After trying to get that library to work, it seemed like it's only a code release and not a system library natively found on devices. The .so is only 25 KB though, so it wouldn't be that large of a file size hit to integrate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants