jean d'arme
jean d'arme

Reputation: 4353

How infact Glide works?

This question may look very basic, but I'm thinking about using Glide in my RecyclerView where I have over 1,000 items. When I open this list - does Glide starts to download them all or only those which I actually have in front of me - so if I will fast scroll from A to E will it download B's ,C's and D's images as well?

Upvotes: 2

Views: 1556

Answers (1)

TWiStErRob
TWiStErRob

Reputation: 46480

Just put a Glide.with.load.into line to your onBindViewHolder and enjoy the performance.

Glide will load only the bound images, and it does so with care. So your adapter is 1000 long, but if only 5 fits on the first screen, then those 5 are bound by RecyclerView, so 5 images are requested. If you start scrolling after 3 are loaded and 2 are in progress of loading, then those 2 will be cancelled when the list item is recycled.

Essentially at any time you'll have about 6 list items in memory, meaning 6 ImageViews and 5-6 of those ImageViews will have images showing in them. If the views are sized the same then the Bitmaps inside will be sized the same and so you can expect some performance increase because if the Bitmap sizes match, Glide will try to re-use them.

Fast scrolling means that all the images will be loaded as soon as the item is bound, but since RecyclerView only keeps a few item layouts inflated, you can expect a fast cancel, maybe even before any request is made to the server, hence only the few images will be actually loaded which are started after scrolling settles down.

You may be able to find more information in the wiki: https://github.com/bumptech/glide/wiki/Resource-re-use-in-Glide

Upvotes: 5

Related Questions