HealthifyMe Tech
Published in

HealthifyMe Tech

Coil Vs Glide

In this article, we will do a comparison between Glide and Coil and make an understanding about which one is better right now.

Glide is a fast and efficient open-source image loading framework for Android which a large number of people are using, whereas Coil is a new library that is gaining popularity these days. Basic functionalities for both the libraries are the same; they both use BitmapFactory to decode the data and use the same Android SDK APIs to read data from the file.

So why is its popularity increasing and how is it different from glide?

It is the only image loading library that is backed by Kotlin Coroutine. It is using libraries like Coroutines, OkHttp, Okio, AndroidX Lifecycles which are already being used in the android project, thus making it lightweight. But to choose which one is good, we have to compare their performance.

How can we compare performance?

I have created two small projects using Glide in one and Coil in the other respectively. This is a simple project which loads five images and sets them in a grid recyclerView. With these projects, we are comparing the image loading speed of each library.

This article is based on the current latest version of Glide and Coil for analysis

For Coil:

implementation("io.coil-kt:coil:1.4.0")

For Glide:

implementation 'com.github.bumptech.glide:glide:4.12.0'

Code to load image and calculate loading time:

For Glide :

fun ImageView.loadImage(url: String, context: Context, position: Int) {
val t = System.currentTimeMillis()
Glide.with(context).load(url).placeholder(R.drawable.ic_launcher_background).into(object : CustomTarget<Drawable>() {
override fun onLoadCleared(placeholder: Drawable?) {
}
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
this@loadImage.setImageDrawable(resource)
Log.d("LoadImage", "$position ${System.currentTimeMillis()-t}")
}
})
}

For Coil :

private fun ImageView.loadImage(url: String, position: Int) {
val t = System.currentTimeMillis()
this.load(url) {
target { drawable ->
this@loadImage.setImageDrawable(drawable)
Log.d("LoadImage", "$position ${System.currentTimeMillis()-t}")
}
}
}

Below are the graphs that tell the time taken to load the image in recyclerView.

To make the test more accurate, we ran the app five times, and then we took the average of each value.

These tests are done on the 4G network device.

There are two tests one with small size images and one with large size:

With Small size images:

When images are loaded for the first time:

When images are loaded from cache:

With Large size images:

When images are loaded for the first time:

When images are loaded from cache:

From these results, for now, in terms of performance Glide is comparatively faster than Coil but if you have used Jetpack, Kotlin Coroutines, OkHttp in your project, then Coil will be more suitable for your project.

--

--

--

The HealthifyMe Tech Blog & Articles

Recommended from Medium

How to Launch Docker Containers with the Official Python Library

First Steps …

Configure Docker in AWS with Help of Ansible

Raft — Taming distributed consensus

How do malloc & free work in C

BUIDL with Textile at ETHDenver 2021

Let’s create a serverless notification system with Amazon API Gateway

Presale NOW LIVE!!!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Singhparakram

Singhparakram

More from Medium

Delegation in Kotlin [2022]

Why use @JvmStatic rather than Companion

Kotlin DSL Basics in Android

What really is Context in Android?