fresco icon indicating copy to clipboard operation
fresco copied to clipboard

Slow reads from disk cache

Open qiaodi opened this issue 11 years ago • 7 comments

Does anybody test the different Adapter in the real environment?Why the fresco is slower than UIL?

Here is my data on Nexus 6 with sample in WIFI:

First run after install:UIL used 1225ms per pic, Fresco 516ms.

First in after reboot:UILused 50ms per piv,fresco 103ms

ReEnter after press back from app:UIL used 0ms, fresco 45ms.

And So on...

SO, in most user case,the fresco is not best in the groups.Do anybody know the reason? Is it release the cache memory when the app going background immediately,and others not?

qiaodi avatar Apr 16 '15 04:04 qiaodi

This is not consistent with results we've found in the sample app. Can you share the URLs you were testing and source snippets?

tyronen avatar Apr 16 '15 09:04 tyronen

Sure. I just modfiy the URLs.

{
  FLog.w(TAG, "onImageLoaderSelect: %d", index);
  if (mCurrentAdapter != null) {
    mCurrentAdapter.shutDown();
    mCurrentAdapter = null;
    System.gc();
  }

mCurrentAdapterIndex = index;
mPerfListener = new PerfListener();
switch (index) {
  case FRESCO_INDEX:
  case FRESCO_OKHTTP_INDEX:
    mCurrentAdapter = new FrescoAdapter(
            this,
            R.id.image_list,
            mPerfListener,
            index == FRESCO_INDEX ?
                ImagePipelineConfigFactory.getImagePipelineConfig(this) :
                ImagePipelineConfigFactory.getOkHttpImagePipelineConfig(this));
    break;
  case GLIDE_INDEX:
    mCurrentAdapter = new GlideAdapter(this, R.id.image_list, mPerfListener);
    break;
  case PICASSO_INDEX:
    mCurrentAdapter = new PicassoAdapter(this, R.id.image_list, mPerfListener);
    break;
  case UIL_INDEX:
    mCurrentAdapter = new UilAdapter(this, R.id.image_list, mPerfListener);
    break;
  case VOLLEY_INDEX:
    mCurrentAdapter = mUseDrawee ?
        new VolleyDraweeAdapter(this, R.id.image_list, mPerfListener) :
        new VolleyAdapter(this, R.id.image_list, mPerfListener);
    break;
  default:
    mCurrentAdapter = null;
    return;
}

mImageList.setAdapter(mCurrentAdapter);

  mImageUrls = new ArrayList<String>();
  mImageUrls.add("http://image.tianjimedia.com/uploadImages/2012/088/10G3888TY0HX_1000x500.jpg");
  mImageUrls.add("http://image.tianjimedia.com/uploadImages/2012/088/CW71CYPXQ6PO_1000x500.jpg");
  mImageUrls.add("http://image.tianjimedia.com/uploadImages/2012/088/3O4P49PRB99R_1000x500.jpg");
  mImageUrls.add("http://image.tianjimedia.com/uploadImages/2012/088/Q172G69LA1RT_1000x500.jpg");
  mImageUrls.add("http://image.tianjimedia.com/uploadImages/2012/088/BFPWRM8PBV74_1000x500.jpg");

  mImageUrls.add("http://img4q.duitang.com/uploads/item/201503/08/20150308190453_nCZCB.jpeg");
  mImageUrls.add("http://cdnq.duitang.com/uploads/item/201503/20/20150320045435_Wh3Ah.jpeg");
  mImageUrls.add("http://cdnq.duitang.com/uploads/item/201503/01/20150301223521_hi8Za.jpeg");
  mImageUrls.add("http://img5q.duitang.com/uploads/item/201503/03/20150303202714_WXYMB.jpeg");
  mImageUrls.add("http://img4q.duitang.com/uploads/item/201502/26/20150226231036_hhPQu.jpeg");
if (mImageUrls != null && !mImageUrls.isEmpty()) {
  updateAdapter(mImageUrls);
} else {
  reloadUrls();
}

updateStats();

} "

qiaodi avatar Apr 17 '15 02:04 qiaodi

And I have checked the source code,I found that Fresco "cache.clearEvictionQueue()" when "OnAppBackgrounded",but the UIL" mImageLoader.clearMemoryCache()" until shutDown. So when app show from the backgroud, the UIL load image from memory cache used 0ms,and Fresco used xx ms.Can we control the time for clear cache??

qiaodi avatar Apr 17 '15 02:04 qiaodi

I will have a look at those URLs.

I actually would call this a bug in UIL. Although your app appears faster with UIL, it's because it is holding onto memory even while in the background. This takes away memory other apps could be using, and makes them slower. It also increases the chances that Android will terminate your app, especially on low-memory devices.

If Fresco did that, the consequence would be even worse, since Fresco is using ashmem memory which is shared among applications. Using a lot of it while in the background would be bad for the entire system.

tyronen avatar Apr 17 '15 11:04 tyronen

Yes. We intentionally clear the memory caches when the app gets backgrounded. This is a proper policy in order to be a good citizen in a larger system. Imagine if all the apps with bunch of images never reclaim their resources. As Tyrone said, the app would likely get killed, which is worse than doing another decode.

plamenko avatar Apr 18 '15 00:04 plamenko

yes, the UIL seems got the unjustified benefit:)

qiaodi avatar Apr 20 '15 06:04 qiaodi

Nothing extra to do here - of course reading from disk cache is slower than reading from memory, and we're doing the correct thing in releasing memory when the application is closed. Let's close the issue. .

IanChilds avatar May 06 '15 15:05 IanChilds