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

Presentation for the Mobicode - Minsk 2016

Presentation for the Mobicode - Minsk 2016

Presentation for the Mobicode - Minsk December 2016

Enrique López Mañas

December 05, 2016
Tweet

More Decks by Enrique López Mañas

Other Decks in Programming

Transcript

  1. Android High Performance Enrique López Mañas Google Developer Expert &

    IT Consultor
  2. How it did start?

  3. Performance "how well a person, machine, etc. does a piece

    of work or an activity" Cambridge
  4. But what is high performance? • Strategies to create efficient

    software Layout Energy and battery Security Multithreading Programming patterns Debugging techniques
  5. Why is important? • User Engagement • Costs • Maintenance

    • Quality
  6. 3 Important Limits 0.1s 1s 10s [Miller 1968; Card et

    al. 1991]:
  7. What this means in Android? ANR

  8. ANR • No response for input event in 5 seconds

    • BroadCast receiver still executing after 10 seconds
  9. How to avoid it? Background operations? Show feedback!

  10. How to avoid it? Splash Screen?

  11. How to avoid it? Calculations? Worker thread!

  12. How to avoid it? Systrace! TraceView!

  13. Debug DDMS

  14. Networking

  15. Layouts TV: 24fps(NTSC), 25fps(PAL) New cam-coders / slow motion: 48fps+

    Blur can occur! Apps: 60fps! every 16 ms!
  16. Layouts

  17. Layouts

  18. Reusing layouts

  19. Reusing layouts

  20. Reusing layouts

  21. ViewStub ViewStub.inflate() View.setVisibility()

  22. ViewStub

  23. Hierarchy Viewer

  24. Profile GPU Rendering

  25. Profile GPU Rendering • Blue: draw • Purple: prepare •

    Red: process • Orange: execute
  26. Memory “the ability to remember information, experiences, and people" Cambridge

  27. Memory - Enumerations

  28. Memory - Enumerations

  29. Memory - Enumerations

  30. Memory - Enumerations

  31. Memory - Enumerations @IntDef

  32. Memory - Enumerations @IntDef

  33. Memory - Enumerations Summary • Unnecessary allocations • AVOID USING

    THEM • Change as much as possible with static final integer values
  34. Memory - Constants Constants in the code should be static

    and final to take advantage of memory savings and to avoid initialization in Java compiler
  35. Memory - Strings

  36. Memory - Strings

  37. Memory - Strings

  38. Memory Leaks “a memory leak is a type of resource

    leak that occurs when a computer program incorrectly manages memory allocations in such a way that memory which is no longer needed is not released.” Wikipedia
  39. Memory Leaks - static fields

  40. Memory Leaks - static fields

  41. Memory Leaks - non-static inner classes

  42. Memory Leaks - WeakReference

  43. Threading “Threading is a method of hair removal originating in

    Asia.” Wikipedia
  44. Threading “is the smallest sequence of programmed instructions that can

    be managed independently by a scheduler” Wikipedia
  45. Threading • AsyncTask • Loader • Threads… Know your war!

  46. Threading - AsyncTask Communicate Worker Thread with UI Does not

    need to communicate UI? Does not need to notify user? DOES NOT NEED ASYNCTASK! If the AsyncTask has all parameters Void, you are only implementing doInBackground() and you do not need an AsyncTask
  47. Threading - AsyncTaskLoader Use it to fetch data Same features

    as AsyncTask… …plus the Activity life-cycle independency and data caching
  48. Threading - AsyncTaskLoader

  49. Threading - Services • Not threads! • Executed in UI

    Thread by default • Never start a long running operation! • Lifecycle
  50. Threading - IntentService • Particular implementation of a Service •

    Execute sequential operations in background • Don’t need to handle the lifecycle
  51. Networking “process of communication between different terminal nodes to exchange

    data” Me
  52. Networking - best practices Latency Gauging

  53. Networking - best practices Batch connections • Wait, collect and

    send • (Analytics)
  54. Networking - best practices Pre-fetch • Download as much as

    possible • (specially if idle connection)
  55. Networking - best practices Queuing connections

  56. Networking - best practices Caching responses

  57. Networking - best practices Last modified

  58. Networking - best practices Exponential back-off

  59. I want your feedback! http://bit.ly/feedbackMobicode @eenriquelopez

  60. None