Save 37% off PRO during our Black Friday Sale! »

Performance myths in android

Performance myths in android

We know reflection or enum are contentious topics, but do they cause *real* performance problems? Let's see!

Ff1a00e40136fecc8a28ebc07018117a?s=128

Javier Gamarra

July 15, 2016
Tweet

Transcript

  1. Performance myths in Android Javier Gamarra / @nhpatt

  2. “Why is this important?”

  3. “Please try again soon!”

  4. Performance is another feature of your app like … login

  5. Performance is … CPU … memory … network … battery

    … smoothness
  6. Always measure first

  7. Tools! --using the right tool for the job

  8. Performance monitors

  9. Android device monitor

  10. GPU Overdraw

  11. Leak Canary

  12. Hierarchy view

  13. Allocation tracker

  14. Traceview

  15. Traceview

  16. GPU profiler

  17. HProf

  18. systrace

  19. Battery historian

  20. External tools (nimbledroid…)

  21. Use an old device

  22. Be pragmatic

  23. FACTS or MYTHS?

  24. “things the community is very passionate about”

  25. lots of things...

  26. iosched

  27. “Own” methods Without games and not counting library methods

  28. Methods in most popular apps -facebook -facebook chat -twitter

  29. 1 DATABASES

  30. None
  31. None
  32. Record actual performance “Write” Espresso tests Rewrite database “layer” Measure

    time to finish Check allocation tracker Check traceview
  33. Use Case 1 (first use) 4,18MB 78,8% parsing 2,5 TV

    seconds 8,8 seconds
  34. Use case 2 (remotely) 4,23MB 13% drawing 1,64 TV seconds

    4,28 seconds
  35. Use case 3 (normal) 4,83MB 13% drawing 2,54 TV seconds

    4,82 seconds
  36. None
  37. “Realm objects can only be accessed on the thread they

    were created”
  38. None
  39. 0’0%

  40. None
  41. ORM performance doesn’t matter

  42. Do NOT choose an ORM because performance

  43. I'll take something 10-20% slower that offers better APIs for

    the very reason that you'll never get close to the limits -- Jake
  44. 2 DI FRAMEWORKS

  45. How slow is reflection?

  46. ... pretty much when done a lot 700 ms to

    NYTimes 660 ms to photobucket ...like JSON/XML parsing
  47. And in DI frameworks?

  48. Synthetic app with 5455 injections: Roboguice: 3923 ms Dagger1: 154ms

    Dagger2: 62 ms
  49. “Roboguice would (...) be (...) a mere 5 times [slower]

    compared to Dagger”
  50. Synthetic app with 5455 injections: Roboguice: 3923 ms Dagger1: 154ms

    Dagger2: 62 ms Directamente: 39ms
  51. 3 REACTIVE LIBRARIES

  52. <BS> about lazyness

  53. Shakespeare plays scrabble

  54. Range

  55. When Not to Use RxJava Small, constant datasets Expensive objects

    Many flatmaps
  56. = 8x slower to iterate

  57. 4 PART04 MICRO OPTIMIZATIONS

  58. Enums -- like 285 bytes lost

  59. “If you use integer constants instead of enums in your

    Android app you are a fool” --Jake Wharton
  60. We use enums regularly because they are safer than Strings

    or ints and their performance downsides are minimal --instagram
  61. OnClickListeners?

  62. How much costs to iterate between 1M likes?

  63. 300 ms 30 MB

  64. JSON parsing Network requests

  65. LAST WORDS

  66. Things I like/UI • Flat layout hierarchy • Merge tags

    • Optimized bitmaps • Inexistent alpha
  67. Things I like/code • WeakReferences • Caches • FlatBuffers •

    Developer Efficiency
  68. “Do the simple thing first … and optimize what matters”

  69. Ok, dagger/rx/ORM is slow but does it matter to you?

  70. ? QUESTIONS? @nhpatt / twitter gmail github ...

  71. THANKS

  72. References • Awesome list • Google+ community • High performance

    programming book • Performance Testing Tools • Speed up your app
  73. “If you care more about performance than correctness why using

    a computer at all?” I can give you the wrong answer faster than any machine ;) -- Mario Fusco
  74. Performance myths in Android Javier Gamarra / @nhpatt