Images in apps and web pages are a bit like electricity, or the internet itself: You don’t notice them until they aren’t there. And when they aren’t there, the experience can be unpleasant.
When an image loads slowly or not at all, it’s easy to blame the network connection or the size of the image. However, there’s actually much more to it than that. An app’s ability to load images quickly depends in large part on the efficiency of its image processing routines, which use complex algorithms to load images as fast as possible without degrading image quality.
Most developers don’t write their own image loading routines for their apps; instead, they use standard code libraries developed for a given platform. In the Android world, the three most popular open-source Android image loading libraries are Fresco, Picasso, and Glide.
The Problem of Image Loading
Any Android app developer who works with images (which is most of them) can rattle off a list of problems inherent in accessing, loading, and displaying images in apps:
- Large-size images often require a good deal of memory to process, which can cause “out-of-memory” (OOM) errors and app crashes.
- Images that are received or processed slowly cause a “laggy” experience for the user. Most users don’t have much patience for these performance hits.
- Processing images for display in a much smaller screen area than the original image also requires an inordinate amount of CPU cycles, which can cause apps to slow down or stop altogether while the CPU tries to get through the intense processing demands.
- Depending on the processing algorithm used, the processed image may suffer from changes in color, sharpness, brightness, and contrast.
- All of these problems are magnified in the case of animated images, because each one is a series of static images.
How Image Loading Libraries Address These Problems
Each of the three image loading libraries take slightly different approaches to solving these problems. Often, developers must contend with a tradeoff among performance, ease of use, and the amount of memory a library occupies. Here are three of the general approaches these libraries take to attack the image-loading problems.
- Memory management: For images that are to be displayed in a smaller space than their original size, loading routines down-samples the image before it is stored in memory. This not only reduces the memory footprint of each image, but saves time by processing the image as it is received rather than waiting until the final byte is loaded.
- Loading: To reduce the number of times images are loaded from their sources, loading libraries rely on cache, either in memory or in storage. Images that are frequently used in apps are loaded from their source once and made available in cache for the app to pull from the next time the image is needed.
- UI performance: Different loading libraries approach the problem of app performance differently. Glide bypasses Android’s “garbage collection” routine (which frees up memory) by reusing an image’s memory space for another image. Fresco uses a special region of the device’s memory for image processing. Among other performance-enhancement options, Picasso enables the use of “placeholder” images for display while the actual image is loaded and processed.
Which One Is Best?
You will not be shocked to learn the answer to this question is “it depends.” Each library has its advantages and disadvantages, and each is best suited for particular scenarios:
- Picasso’s library size is smaller than that of the others, but a first-time image load can take much longer. Its main advantage is that it is extremely easy to implement in app code—typically one line. Thus, it’s best for apps that need a small memory footprint and don’t have to process lots of large images.
- Glide’s loading times are faster and it uses a small amount of memory for cache, but the library size is quite large. It, too, is easy to implement. Glide might be a better alternative to Picasso when memory footprint is less of a concern or more and larger images need to be processed.
- Fresco’s loading times are very fast and the library has lots of additional functionality and options, but coding with it is more complex. This option is better for image-heavy apps built by highly skilled developers.
At AndPlus, we are keenly aware of the tradeoffs among the different image loading library options and know how to evaluate and select the right one for your app. If you have a great idea for an app, give us a call—you can rest assured we will provide the right technology to implement it.