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

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!

Javier Gamarra

July 15, 2016
Tweet

More Decks by Javier Gamarra

Other Decks in Programming

Transcript

  1. Performance myths
    in Android
    Javier Gamarra / @nhpatt

    View Slide

  2. “Why is this important?”

    View Slide

  3. “Please try again soon!”

    View Slide

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

    View Slide

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

    View Slide

  6. Always measure first

    View Slide

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

    View Slide

  8. Performance monitors

    View Slide

  9. Android device monitor

    View Slide

  10. GPU Overdraw

    View Slide

  11. Leak Canary

    View Slide

  12. Hierarchy view

    View Slide

  13. Allocation tracker

    View Slide

  14. Traceview

    View Slide

  15. Traceview

    View Slide

  16. GPU profiler

    View Slide

  17. HProf

    View Slide

  18. systrace

    View Slide

  19. Battery historian

    View Slide

  20. External tools (nimbledroid…)

    View Slide

  21. Use an old device

    View Slide

  22. Be pragmatic

    View Slide

  23. FACTS
    or
    MYTHS?

    View Slide

  24. “things the community
    is very passionate about”

    View Slide

  25. lots of things...

    View Slide

  26. iosched

    View Slide

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

    View Slide

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

    View Slide

  29. 1 DATABASES

    View Slide

  30. View Slide

  31. View Slide

  32. Record actual performance
    “Write” Espresso tests
    Rewrite database “layer”
    Measure time to finish
    Check allocation tracker
    Check traceview

    View Slide

  33. Use Case 1 (first use)
    4,18MB
    78,8% parsing
    2,5 TV seconds
    8,8 seconds

    View Slide

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

    View Slide

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

    View Slide

  36. View Slide

  37. “Realm objects can only be
    accessed on the thread
    they were created”

    View Slide

  38. View Slide

  39. 0’0%

    View Slide

  40. View Slide

  41. ORM performance
    doesn’t matter

    View Slide

  42. Do NOT choose an ORM
    because performance

    View Slide

  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

    View Slide

  44. 2
    DI FRAMEWORKS

    View Slide

  45. How slow is reflection?

    View Slide

  46. ... pretty much when done a lot
    700 ms to NYTimes
    660 ms to photobucket
    ...like JSON/XML parsing

    View Slide

  47. And in DI frameworks?

    View Slide

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

    View Slide

  49. “Roboguice would (...) be (...) a mere 5
    times [slower] compared to Dagger”

    View Slide

  50. Synthetic app with 5455 injections:
    Roboguice: 3923 ms
    Dagger1: 154ms
    Dagger2: 62 ms
    Directamente: 39ms

    View Slide

  51. 3
    REACTIVE
    LIBRARIES

    View Slide

  52. about lazyness

    View Slide

  53. Shakespeare plays
    scrabble

    View Slide

  54. Range

    View Slide

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

    View Slide

  56. = 8x slower to iterate

    View Slide

  57. 4
    PART04
    MICRO OPTIMIZATIONS

    View Slide

  58. Enums
    -- like 285 bytes lost

    View Slide

  59. “If you use integer constants instead of
    enums in your Android app you are a
    fool” --Jake Wharton

    View Slide

  60. We use enums regularly because
    they are safer than Strings or ints
    and their performance downsides
    are minimal --instagram

    View Slide

  61. OnClickListeners?

    View Slide

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

    View Slide

  63. 300 ms
    30 MB

    View Slide

  64. JSON parsing
    Network requests

    View Slide

  65. LAST
    WORDS

    View Slide

  66. Things I like/UI
    ● Flat layout hierarchy
    ● Merge tags
    ● Optimized bitmaps
    ● Inexistent alpha

    View Slide

  67. Things I like/code
    ● WeakReferences
    ● Caches
    ● FlatBuffers
    ● Developer Efficiency

    View Slide

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

    View Slide

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

    View Slide


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

    View Slide

  71. THANKS

    View Slide

  72. References
    ● Awesome list
    ● Google+ community
    ● High performance
    programming book
    ● Performance Testing
    Tools
    ● Speed up your app

    View Slide

  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

    View Slide

  74. Performance myths
    in Android
    Javier Gamarra / @nhpatt

    View Slide