Tran Vu Tat Binh
I’ve done all kind of micro-optimizations, use goodalgorithms, choose the right data structures but stillgot serious perfo...
Performance issues? The overall application runs slow. The application makes otherapplications on phone run slower (yes,...
Some interesting points Number of threads Organizing threads Multi-threading and network Mobile network under the hood
Number of threads Using too many threadsAfter launch Rush hour
Number of threads Using too many threads: Overhead Hard to control Less time for each thread Concurrency
Number of threads Using too few threads: Not take advantage of system resources Not so responsive
Number of threadsSo how many?Flexible and should not be a fixednumber, see the next “Organizingthreads” for more details.
Organizing threads Usually, there are 3 kinds of task Blocking UI task Updater task Lazy media task
Organizing threads Blocking UI task○ When there are no other dataon screen○ When user definitely have towait for updated ...
Organizing threads Updater task○ Updating / refreshing○ Loading more○ User can still interact withexisted data on screen○...
Organizing threads Lazy media task○ Thumbnails for existed data○ A list/grid of imagesShould be 2 thread pools: onefor d...
Organizing threads Lazy media task (con.) Usually most heavy task  focus optimizing Why separating into downloading an...
Organizing threads Decoding pool sizeNUMBER_OF_CORES = Runtime.getRuntime().availableProcessors();mDecodeThreadPool = new...
Organizing threads Downloading pool size Normal:○ Fixed size (may be 8 like in some tutorials) More optimized:○ 2G – si...
Organizing threads Why variable size is better choice:2G pool size 22G pool size 42G pool size 8
Organizing threads Why variable size is better choice:3G pool size 4 3G pool size 83G pool size 24
Organizing threads Facts: Each connection has a limited bandwidth The phone’s network connection has aoverall limited b...
Organizing threads Downloading pool size Too small size○ Waste network bandwidth○ Drain battery life if using mobile net...
Organizing threads Conclusion: Blocking UI task – 1 thread Updater task – 1 thread pool size 2 - 4 Lazy media task – 2...
Mobile network under the hood Online applications like messenger,news reader, social app or onlinegame… some got serious ...
Mobile network Typical 3G wireless radio state machine (source)
Mobile network Messenger application○ Small data message○ Transferring morefrequently○ No fixed schedule
Mobile network Online game○ Small data message○ Transferring much morefrequently○ Usually fixed schedule○ Responsiveness ...
Mobile network Social app News reader Photo sharing Music app…
Mobile network Optimize data to transfer (as always) Batch operation Prefetch When receive, if need to transmit thendo...
Q&A
Thank you!
Upcoming SlideShare
Loading in …5
×

Vietnam Mobile Day 2013: For Higher Performance Mobile Applications

1,178 views

Published on

Bài chia sẻ của anh Trần Vũ Tất Bình tại hội thảo Vietnam Mobile Day 2013 tổ chức tại TP.Hồ Chí Minh vào ngày 18/05/2013.

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,178
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Vietnam Mobile Day 2013: For Higher Performance Mobile Applications

  1. 1. Tran Vu Tat Binh
  2. 2. I’ve done all kind of micro-optimizations, use goodalgorithms, choose the right data structures but stillgot serious performance issues in my mobile apps.Our online game took about 10minutes to download 25 MB resourcesusing 3G in the old version
  3. 3. Performance issues? The overall application runs slow. The application makes otherapplications on phone run slower (yes, itcan) Users feel the application slow. Be strict: it’s also performance issue ifwe can do much better but we don’t
  4. 4. Some interesting points Number of threads Organizing threads Multi-threading and network Mobile network under the hood
  5. 5. Number of threads Using too many threadsAfter launch Rush hour
  6. 6. Number of threads Using too many threads: Overhead Hard to control Less time for each thread Concurrency
  7. 7. Number of threads Using too few threads: Not take advantage of system resources Not so responsive
  8. 8. Number of threadsSo how many?Flexible and should not be a fixednumber, see the next “Organizingthreads” for more details.
  9. 9. Organizing threads Usually, there are 3 kinds of task Blocking UI task Updater task Lazy media task
  10. 10. Organizing threads Blocking UI task○ When there are no other dataon screen○ When user definitely have towait for updated data onlyShould be a single thread withhigh priority since user can notproceed if task is not done.
  11. 11. Organizing threads Updater task○ Updating / refreshing○ Loading more○ User can still interact withexisted data on screen○ Can move to other screenwithout finishing taskShould be a thread pool(suggest size 2-4)
  12. 12. Organizing threads Lazy media task○ Thumbnails for existed data○ A list/grid of imagesShould be 2 thread pools: onefor downloading and one fordecoding
  13. 13. Organizing threads Lazy media task (con.) Usually most heavy task  focus optimizing Why separating into downloading anddecoding○ Images might be in local cache already anddecoding usually much faster thandownloading, so don’t let downloading slowdown the progress○ Decoding pool size should be based on CPUcores○ Downloading pool size should be based onnetwork status
  14. 14. Organizing threads Decoding pool sizeNUMBER_OF_CORES = Runtime.getRuntime().availableProcessors();mDecodeThreadPool = new ThreadPoolExecutor(NUMBER_OF_CORES,NUMBER_OF_CORES, KEEP_ALIVE_TIME, KEEP_ALIVE_TIME_UNIT,mDecodeWorkQueue);
  15. 15. Organizing threads Downloading pool size Normal:○ Fixed size (may be 8 like in some tutorials) More optimized:○ 2G – size 4○ 3G – size 8○ 4G – size 16 (or more)○ WIFI – size 8 Much more optimized:○ Based on network speed, increasing size ifcan still download faster, decreasing size ifstill not slower, until get the best size.
  16. 16. Organizing threads Why variable size is better choice:2G pool size 22G pool size 42G pool size 8
  17. 17. Organizing threads Why variable size is better choice:3G pool size 4 3G pool size 83G pool size 24
  18. 18. Organizing threads Facts: Each connection has a limited bandwidth The phone’s network connection has aoverall limited bandwidth There are network latency causing “gaps”while downloading
  19. 19. Organizing threads Downloading pool size Too small size○ Waste network bandwidth○ Drain battery life if using mobile network○ Slow Too large size○ Take more time to show individual image (notoverall images on screen)  users feel slow○ TCP congestion control○ Slower to start downloading new images whenscrollingVariable size based on network status is goodchoice but need more time to implement
  20. 20. Organizing threads Conclusion: Blocking UI task – 1 thread Updater task – 1 thread pool size 2 - 4 Lazy media task – 2 thread pools○ 1 thread pool for decoding size = available cores○ 1 thread pool for downloading size based onnetwork status
  21. 21. Mobile network under the hood Online applications like messenger,news reader, social app or onlinegame… some got serious issues whenusing mobile network○ Battery drain○ Slow response
  22. 22. Mobile network Typical 3G wireless radio state machine (source)
  23. 23. Mobile network Messenger application○ Small data message○ Transferring morefrequently○ No fixed schedule
  24. 24. Mobile network Online game○ Small data message○ Transferring much morefrequently○ Usually fixed schedule○ Responsiveness isimportance
  25. 25. Mobile network Social app News reader Photo sharing Music app…
  26. 26. Mobile network Optimize data to transfer (as always) Batch operation Prefetch When receive, if need to transmit thendo quick If possible, do at the same time withother apps
  27. 27. Q&A
  28. 28. Thank you!

×