December 19, 2016

Whenever it comes to Image Loader two libraries comes to our mind, Picasso and Glide. But which library is more efficient for our projects. Lets compare them.

IMPORTING TO PROJECT:

Both Picasso and Glide are in the jCenter, Both can be imported in this way.


// For Picasso
dependencies { 

	compile 'com.squareup.picasso:picasso:2.5.1'

}

// For Glide
dependencies {

	compile 'com.github.bumptech.glide:glide:3.5.2'

}

USAGES:

Both Picasso and Glide are very similar in using. Below is the way to load an image to an ImageView.


Picasso.with(context).load(URL).into(imageView);

Glide.with(context).load(URL).into(imageView);

The way of loading an image to an imageView is quite similar, but in details Glide is far better than Picasso. Here, Picasso can only accept Context context, like Picasso.with(context), but on the other hand Glide accept Context context, Activity activity, FragmentActivity fragmentActivity, Fragment fragment.

If we are passing Activity or Fragment to Glide, then the image loading would be integrated with Activity/Fragment’s lifecycle. So, it is better to pass the Activity or Fragment to Glide.

IMAGE QUALITY:

Image loaded by the Glide are not god compared with the Picasso. Picasso default bitmap Format is ARGB_8888, on the other hand Glide’s default Bitmap Format is RGB_565, which is consuming just 50% memory footprint compared to Picasso.

Though, the image quality is not good, we can switch the Bitmap Format to ARGB_8888 by creating a new which will extend GlideModule. Even on switching the Bitmap Format to a higher one the memory consumption will be still lower than the Picasso. The reason is Picasso loads the full-size image (1920X1080 pixels) into the memory and let GPU does the real-time resizing when drawn. On the other hand Glide loads the exact ImageView size(768X432 pixels) into the memory. However, we can change the behavior of Picasso to do the same by using .resize() method.

DISK CACHING:

While experimenting, when I checked the cache folder I found that Glide cached the ImageView size (768X432 pixels), while Picasso cached the same image as (1920X1080 pixels). Picasso will cache only the full-size image. Glide will act differently, it will caches separate file for each size of ImageView. For Example, suppose there is an ImageView with 200X200 pixels, and on the other page the ImageView is having 100X100 pixels, and in both the ImageView the same Image is to be set. Then for this I’ve to download the same image twice. However Glide can cache both the full-size Imae and resized on with this command.


Glide.with(this).load(URL)
  .diskCacheStrategy(DiskCacheStrategy.ALL)
  .into(imageView);

Now the next time image is requested to show on any ImageView, the full-size image would be loaded from cache, resized and then cached. The way of loading an image in Glide is way faster than Picasso.

ADVANTAGE OF GLIDE OVER PICASSO:

Glide has one major advantage over Picasso, and that advantage is Glide has the ability to load GIF animation. Since, Glide is designed to work perfectly with Activity/Fragment’s lifecycle so the animation would be automatically paused and resumed along with Activity/Fragment’s state. Besides GIF animation loading, Glide is also able to decode any local video file to a still image. We can configure the way image appears by using R.animator, while Picasso supports only one animation, and that is fading in.

LIBRARY’s SIZE:

Picasso (v2.5.1)’s size is around 118 KB, while Glide (v3.5.2)’s is around 430 KB.

METHOD COUNT:

Picasso has 480 methods, while Glide has 2678 methods.

CONCLUSION:

There is some trade off between Picasso’s and Glide’s way of disk caching. You can choose the way fit your app’s requirement best. For me, I prefer Glide to Picasso since it is far faster although it needs more space to cache the image.