0

I am facing an issue where Picasso is unable to rapidly load images.

There are 3 ImageViews which display left, middle and the right images. On fast forward/backward, for a given time point, the left, middle and the right are chosen and displayed in the three box.

Here is the initialization. OkHttp cache is 100MB along with 99MB of LruCache

new Picasso.Builder(getApplicationContext())
                .downloader(new OkHttp3Downloader(picassoOkHttpClient))
                .memoryCache(new LruCache(99999999))
                .build();

The number of images over which the window moves is 3000+. So I preload the images as

picasso.load(imageUrl).fetch();

Average image size is 10KB - 320x180 so it amounts to 35MB which is less than 99MB LruCache.

When the rapidly cycling through works, many of the images are GREEN (from MEMORY) and BLUE (from DISK) but then after few rapid cycles, the 3 images freeze or become very slow. At this time most of the images are BLUE. App is still responding. No OutOfMemory or any other exception.

android:largeHeap option is also enabled.

The hit ratio in the Picasso stats is very low. 150/3000.

The images are loaded as

picasso.load(leftUrl)
.noFade()
.noPlaceholder()
.into(leftImageView);

picasso.load(middleUrl)
.noFade()
.noPlaceholder()
.into(middleImageView);

picasso.load(rightUrl)
.noFade()
.noPlaceholder()
.into(rightImageView);

Issue 1 -> Picasso takes several minutes to download 3000+ images. Images load fast enough on other platforms and there is plenty of bandwidth (high enough to stream 4K)

Issue 2 -> Even after letting Picasso take its own time and finish loading all the images, it still freezes. Green ones are fast, Blue slower and then Blue ones freeze.

PS: I understand that "inflated" images will be much larger in size and will easily cross the 99MB bounds. That is why only some are green while most of them are blue.

Hado99
  • 555
  • 6
  • 15

2 Answers2

0

The only reason I can understand fro your problem is that you are using images of very high resolution with huge size. My suggestion for you is to resize the images while you are loading those images. Something like that:

Picasso.with(getApplicationContext()).load(filePath).resize(400,400).centerCrop().into(imageView);

Hope this will help!

Zohaib Hassan
  • 984
  • 2
  • 7
  • 11
  • Actually, images are JPG are quite compressed. 320x180 image is 10KB. Even with half the number of images, 1500, performance is terrible. – Hado99 May 11 '17 at 21:53
  • Tried with resize(320, 180) but no significant difference. – Hado99 May 11 '17 at 22:19
  • You are loading 3000 images all at once? – Zohaib Hassan May 11 '17 at 22:38
  • Yes. They have to be. Network bottleneck could severely affect the display causing images to be skipped. Even disk retrieval suffers if Picasso is asked to load too quickly. Anything less than 500ms causes slowdown while loading from disk (blue indicator) – Hado99 May 11 '17 at 22:53
  • Why don't you load them step by step, like one after another. Otherwise you'll be facing this issue. I don't know about your project requirement. But I can suggest is to load images in chunks not all together. Let's load first image an when it has been load then go for the second one, or maybe load first 100 images and when 100 have been loaded then go for next hundred. Check this: http://stackoverflow.com/questions/26548660/how-to-listen-for-picasso-android-load-complete-events In "OnSuccess()" method put your condition to check if position is 100 or something. – Zohaib Hassan May 14 '17 at 20:28
  • Sorry for not being clear. By loading all at once means, I use `fetch()` to preload them. This distributes the loaded images on memory and disk cache. Most on disk while few on memory. Then when needed, the images are "accessed" 3 at a time as we move back and forth on the timeline. – Hado99 May 15 '17 at 18:17
0

Try using another image loading library? Maybe the flaw is simply with Picasso. Personally i've never been fond of Picasso as it always had some issues. I've started using Glide, and can't find a single bad thing about it. It supports all kinds of caches and transformations, and it does it extremely well.

Examples:
- Glide
- UniversalImageLoader
- Fresco

Moonbloom
  • 7,738
  • 3
  • 26
  • 38
  • Thanks. I have been thinking about it out of desperation. I just want to rule out every possibility with Picasso. Still banging my head against it but no solution. – Hado99 May 11 '17 at 21:54
  • Although Glide doesn't completely solve my problem, it is much better than Picasso at least because of the default Bitmap format it uses. Way fewer misses, skips and freezes with the same/similar configurations. Even after forcing Picasso to use the Glide's default format, RGB_555, it still isn't as fast. – Hado99 May 15 '17 at 18:20