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

Android Optimization at Development level

Android Optimization at Development level

This talk discusses the importance of thinking about performance during development, instead of ignoring it completely with the excuse of "premature optimization."

Oliver Mensah

November 24, 2018
Tweet

More Decks by Oliver Mensah

Other Decks in Technology

Transcript

  1. Oliver Mensah NSP, Agro Innova CoLead, DevC Accra Guest Auth0,

    Auth0 Accra Ditch “Premature Optimization” & start thinking in optimization During Development
  2. “Before you jump in, you should realize code optimization is

    not the first priority in your application development. Delivering a good user experience and focusing on code maintainability should be among your top priorities. In fact, code optimization should be one of your last priorities, and may not even be part of the process altogether. However, good practices can help you reach an acceptable level of performance without having you go back to your code, asking yourself “what did I do wrong?” and having to spend additional resources to fix it.” - Herve Guihot, Pro Android Apps Performance Optimization
  3. Mobile devices have less resources; Memory, battery life,CPU, etc. hence

    so many trade-offs during development. What are your trade-offs? Accra
  4. Common Trade-offs - Trade-off on code readability and maintainability -

    Trade-off on cost - Trade-off on speed of development - Trade-off on performance * Efficient use of resources * Ensuring responsiveness * Not most developers’ favorite
  5. Performance Tips - Memory Efficiency * Choosing the Appropriate Data

    Types / Data Structures * Using Static Members over Member Variables * Using Enhanced for loops - Responsiveness * Lazy Initialization * Background Task * Slow Network Access * Slow File Access
  6. 1 Choosing the Appropriate Data Type/ Data Structure - What

    are they? - Appropriate Use Cases * Ordering Stack Queues Arrays Arraylist * Uniqueness Set * Pairs Map SparseArray(Solves Autoboxing of Maps)
  7. A deeper look into common Mobile Device Resource * Memory

    * Memory Footprints * Garbage Collection
  8. Android Responsiveness - Responsiveness at the core of Android *

    Keep the Main Thread for activity related task UI Rendering, Event Handlers * Spawn Separate Thread for Long Processes - Lack of it leads to Android Not Responding Error * A process is blocked when it exceeds 200 milliseconds on job * Giving the user the chance to kill your application
  9. Strategies for Maintaining Responsiveness - Spawn a new thread *

    Thread/Looper/Handler * HandlerThread * AsyncTask * Thread pools * Native threads
  10. Debugging Performance - Android Monitor This is a tool built

    into Android Studio to monitor operations on * Network * CPU * GPU * Memory. - Hierarchy Viewer Tells how your XML views are rendered