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

Speed up your app (Droidcon NYC 2015)

Speed up your app (Droidcon NYC 2015)

With a great variety of tools for optimizing your Android apps, it's easy to get lost and find it hard to even start working on the problem. This talk will cover how to approach a performance issue by picking the right tool for the job, analyzing the data and track down the culprit. We'll review case studies using Systrace, Traceview, Hierarchy Viewer, Allocation Tracker, Eclipse MAT and others, demonstrating variety of problems that many apps suffer from, and how to solve them.

Video is available here: https://www.youtube.com/watch?v=v3DlGOQAIbw

107169775092a3ef4ae94fad5695613a?s=128

Udi Cohen

August 27, 2015
Tweet

Transcript

  1. Speed up your app Udi Cohen

  2. MEASURE SLOW DEVICE TRADE-OFFS The Rules: ALWAYS USE CONSIDER

  3. Systrace

  4. None
  5. None
  6. None
  7. None
  8. None
  9. None
  10. EXAMPLE SYSTRACE

  11. None
  12. Frame >16ms

  13. None
  14. Traceview

  15. None
  16. NAME List of all executed methods

  17. INCLUSIVE CPU TIME Time spent on the method and all

    methods it calls
  18. EXCLUSIVE CPU TIME Time spent just in the method itself

  19. INC/EXC REAL TIME Actual time the method took from start

    to finish
  20. METHOD CALLS Number of times the method was called and

    how long each call took (avg.)
  21. EXAMPLE TRACEVIEW

  22. None
  23. None
  24. None
  25. None
  26. ??

  27. Memory Profiling

  28. None
  29. GC

  30. Call GC Dump Heap Alloc Tracker

  31. HEAP SNAPSHOT

  32. Eclipse MAT

  33. Call GC Dump Heap Alloc Tracker

  34. None
  35. Memory Tips Bitmap’s pixel format HashMap vs. ArrayMap / Sparse*Array

    Context Awareness
  36. LeakCanary

  37. GPU Profiling

  38. None
  39. None
  40. None
  41. None
  42. None
  43. < <=

  44. adb shell dumpsys gfxinfo <pkg name> <=

  45. None
  46. Hierarchy Viewer

  47. None
  48. Render times •Measure, Layout and Draw. •For the view and

    its children
  49. Measure Performance Indicators Layout Draw Green: view is in the

    faster 50% Yellow: view is in the slower 50% Red: view is the slowest in the tree
  50. Overdraw

  51. None
  52. 1x Overdraw 2x Overdraw 3x Overdraw 4x Overdraw+ No Overdraw

  53. Too much..

  54. Alpha

  55. setAlpha() ALPHA The direct approach

  56. setAlpha() ALPHA The complex approach

  57. Alpha Tips TextView setTextColor() instead of setAlpha() ImageView setImageAlpha() instead

    of setAlpha() Custom Views Handle alpha yourself by overriding onSetAlpha() Override hasOverlappingRendering()
  58. Hardware Acceleration

  59. Using Hardware Layers OR

  60. EXAMPLE HW LAYERS

  61. View Pager ! Parallax effect for the pages background !

    Views in the page are moved as we scroll pages
  62. Enabling “Show hardware layers updates”

  63. None
  64. Small hack to disable HW layers for ViewPager pages

  65. More

  66. More Resources Android Performance Patterns playlist on YouTube My blog:

    http://www.udinic.com Android Performance Patterns Google+ community (#PerfMatters)
  67. Thank you! @udinic +UdiCohen www.udinic.com Udi Cohen