7

I am using UrlImageViewHelper in order to load pictures in an adapterview.

My adapter is:


@Override
public View getView(int position, View convertView, ViewGroup parent) {              
    if(convertView==null){
        convertView=new SquaredImageView(getContext());
    }
    SquaredImageView view= (SquaredImageView) convertView;
    final long time=System.currentTimeMillis();
    UrlImageViewHelper.setUrlDrawable(view,getItem(position).getLook_picture(),
           R.drawable.placeholder_bkp, -1,new UrlImageViewCallback() {
                   @Override
                   public void onLoaded(ImageView imageView, Bitmap loadedBitmap, 
                                              String url, boolean loadedFromCache) {
                       Log.d(TAG,"time : "+ (System.currentTimeMillis()-time));
                   }
    });
    return view;
}

I am downloading and displaying large pictures (620x620 jpg) in a full width list. They are slow the first time it is downloaded/displayed. This problem is not anymore occuring after an upgrade to android 4.2. on HTC one.

I tried to profile the calls and I believe that during the very long calls, it hangs reading the socket inputstream.

Has anyone a clue as to why there is such a difference in performance between the two platforms?


Logcat outputs: (timings under 100 ms are usually duplicates)

android 4.1.2 Galaxy SIII mini

  • time : 3217
  • time : 4782
  • time : 124
  • time : 56
  • time : 168
  • time : 84
  • time : 102
  • time : 2819
  • time : 2703
  • time : 154
  • time : 2468
  • time : 81
  • time : 40
  • time : 52
  • time : 2495
  • time : 37
  • time : 2007
  • time : 58
  • time : 38
  • time : 119
  • time : 80
  • time : 44
  • time : 2419
  • time : 1651
  • time : 40
  • time : 2766
  • time : 90
  • time : 1889
  • time : 183
  • time : 2515
  • time : 58
  • time : 3345
  • time : 2661
  • time : 81
  • time : 2434
  • time : 119

mostly above 1.5 sec. user needs to scroll items one by one to see the picture

On android 4.3 nexus 4:

  • time : 47
  • time : 1111
  • time : 154
  • time : 46
  • time : 124
  • time : 115
  • time : 150
  • time : 201
  • time : 332
  • time : 366
  • time : 450
  • time : 82
  • time : 167
  • time : 81
  • time : 150
  • time : 224
  • time : 224
  • time : 143
  • time : 185
  • time : 66
  • time : 183
  • time : 66
  • time : 218
  • time : 98
  • time : 169
  • time : 49
  • time : 148
  • time : 65
  • time : 64
  • time : 60
  • time : 169
  • time : 51

consistently under 500 ms, list is usable

alaeri
  • 344
  • 3
  • 16
  • Maybe the allocation of the UrlImageViewCallback within the getView method, slows it down, could you try pass it the same instance, over and over again? – Kirill Kulakov Aug 09 '13 at 14:30
  • The time spent in the getview method of the adapter is consistently below 5 ms. If i remove the whole callback, I see the same results. (one is very slow, the other one is fast). I dont think the callback is the cause of the problem. – alaeri Aug 16 '13 at 13:54
  • You're certain this isn't simply just download time? How big are the files? The latter set of values indicate they're probably being loaded from cache. – koush Aug 28 '13 at 17:31
  • Hi koush :) The files are between 70 and 110 KB and are expanded to be – alaeri Aug 29 '13 at 15:44
  • 1
    I supspect this a platform bug since we are experiencing exactly same thing on Samsung Galaxy Note 10" and Google Nexus S both running Android 4.1.2. On newer versions of Android the problem doesn't exist, just like original poster said. – Antti Nov 01 '13 at 06:02

2 Answers2

2

This has nothing to do with the OS running on the phone. The probable reason and the most possible one is the amount of RAM memory that is being consumed by other applications on the device. For testing purposes try running the same code on a new device that has not many apps running on it..

sschrass
  • 7,014
  • 6
  • 43
  • 62
  • I believed it was the case before we updated a htc one device to 4.2 and everything sped up. Unless the amount of ram allocated to apps increased between 4.1 and 4.2 on htc one. I dont have the device anymore to check. – alaeri Aug 16 '13 at 13:24
  • I am awarding you the bounty. It had one upvote and this is still the most probable cause. Still, I dont get why it changed after the upgrade on htc one. – alaeri Aug 16 '13 at 13:46
1

(I do not expect this answer to take the bounty)
UrlImageViewHelper uses HttpURLConnection to make the http calls to the web server serving the images. We have used HttpURLConnection (and tried most of the other classes to do http gets) we found it to be the least flaky (particularly on Android 2.3) of the generally flaky classes (e.g. the org.apache.http stuff etc). At one point I used a protocol analyser (tcpdump or tshark) on our web-server and found that the ACKs weren’t coming back in a timely fashion, I think (this was over a year ago) I found more or less the same thing on WiFi and cell data (t-mobile GSM). I concluded there were low level problems in these classes, perhaps problems with Dalvik itself. Again, I don't expect this answer to take the bounty, I have not attempted to prove my assertions, I am merely recounting how far I got in my investigation a similar problem.

tallen
  • 677
  • 6
  • 17
  • search stackoverflow for things related to HttpURLConnection – tallen Aug 09 '13 at 16:04
  • I tried to use picasso to replace UrlImageViewHelper and I had the same behaviour :( Picasso use okhttp lib. It might be the case that it is affected by the same low level issue but it is not sure – alaeri Aug 16 '13 at 13:29
  • [this question](http://stackoverflow.com/questions/14717752/httpurlconnection-very-slow?lq=1) might have the same problem but no one answered :( I have awarded the bounty to the other answer but I want to thank you for your help. I will try to update the question next week with test results. – alaeri Aug 16 '13 at 13:50