Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What could make the loading slow in android 4.1.X and not on 4.2?

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

like image 916
alaeri Avatar asked Aug 07 '13 09:08

alaeri


2 Answers

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..

like image 198
Glenford Fernandes Avatar answered Nov 20 '22 17:11

Glenford Fernandes


(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.

like image 31
tallen Avatar answered Nov 20 '22 16:11

tallen