📜 ⬆️ ⬇️

Saving memory: Picasso vs UniversalImageLoader

Hi, Android developers!
I think each of us is faced with downloading images by URL. The easiest way to solve this problem is to use a ready-made third-party library. As a rule, Universal Image Loader (UIL), Picasso turns out to be one of such ready-made solutions. When I ask the developer why he chose this or that library, I usually get different answers. For example, "Picasso / UIL has no problems with memory leaks," or "Square does only the right things," or just "Yes, I use UIL, it works — and well."
So, I wondered: which of these 2 libraries makes the best use of memory? I am using UIL and have a problem with OutOfMemory on older devices. Perhaps Picasso is a medicine?
So the idea of ​​this benchmark appeared.


The purpose of testing: to determine which of the libraries (UIL or Picasso) uses the minimum memory device.

Test cases:
- Download small images (240x240)
- Download large images (> 400px according to any of the dimensions)
- Download large images and convert their size to the dimensions of ImageView
- Download small images and display them as a round picture
- Download large images and display them in RGB565 configuration
')
Test procedure:
As a list, use a 2-column GridView. The adapter is configured separately for each test case. In the adapter, we return a list of previously prepared URLs, thus creating the same testing conditions.
With a period of 1 second, the list automatically makes one pass down, and then up in 4-step increments. Each step measures the memory used by the application.
We measure the used memory in 3 stages for each test case:
- first run - with a clean application cache;
- second launch: without closing the application after the first pass;
- the third launch - after re-opening the application without clearing the cache.
At the end of the test case, I additionally recorded the size of the cache, which is also important for older devices.

Benchmark sources can be found here.
github.com/artemmanaenko/ImageLoadersTest . The project is compiled under Gradle.

So, below are the results for each test case. The Y axis is the memory used by the application in MB. X axis - the time of the test case.

Loading small images

image
Cache size: Picasso = 1.39 MB, UIL = 1.17 MB

Download large images

image
Cache size: Picasso = 3.67 MB, UIL = 5.44 MB

Download large images with up to image size conversion

image
Cache size: Picasso = 3.67 MB, UIL = 5.44 MB

Loading small images and cropping them to a round image

image
Cache size: Picasso = 1.39 MB, UIL = 1.17 MB

Downloading large images and displaying them in the RGB565 configuration

image

The results of experiments with large pictures impressed me, and I decided that it was worth trying to configure the UIL configuration. In order not to heavily load memory with cache - I tried to disable the cache in UIL from RAM. And, as an option, set the cache size of the image - no more than half the screen.

image

Based on the experiment, I made the following conclusions:

Source: https://habr.com/ru/post/218453/


All Articles