Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android ListView performance tuning

Android ListView performance tuning

just a little sharing

billynyh

April 17, 2014
Tweet

Other Decks in Programming

Transcript

  1. What is heavy? • Inflate view ◦ reuse convertView •

    findViewById ◦ ViewHolder pattern • Decode bitmap ◦ background thread • Load drawable? ProgressBar? • More?
  2. • Object creation • String manipulation ◦ timestamp -> human

    time ◦ like count, comment count ◦ image path • Log • Autoboxing, unboxing (Integer vs int)
  3. Drawing • Keep the view hierarchy flat ◦ faster measure

    ◦ careful about 2 pass measure layout ▪ RelativeLayout ▪ LinearLayout with weight • Over draw • All-in-one vs separate view for each type
  4. GPU profiling • Draw is the time spent building display

    lists in Java. It indicates how much time is spent running methods such as View.onDraw(Canvas). • Process is the time spent by Android’s 2D renderer to execute the display lists. The more Views in your hierarchy, the more drawing commands must be executed. • Execute is the time it took to send a frame to the compositor. This part of the graph is usually small. • Reminder: to render smoothly at 60 fps, each frame must take less than 16 ms to complete. http://www.curious-creature.org/2012/12/01/android-performance-case-study/
  5. onScroll • Infinite scroll • Pre download images ◦ file.exists()

    ? • Add rate limit for heavy tasks • Dont notifyDataSetChanged during scroll ◦ dont append data during scroll
  6. Image cache • Dont create one thread for each image

    ◦ more memory used when decode multi image together ◦ more GC • AsyncTask or HandlerThread • LRU cache ◦ http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html
  7. GC • Pause the system a few/many ms • cause

    lag when scrolling • cant do anything about it • Work around? ◦ call System.gc() when idle ◦ System.gc() - Note that this is a hint only. There is no guarantee that the garbage collector will actually be run.