Slide 1

Slide 1 text

Oliver Mensah NSP, Agro Innova CoLead, DevC Accra Guest Auth0, Auth0 Accra Ditch “Premature Optimization” & start thinking in optimization During Development

Slide 2

Slide 2 text

Motivation For The Talk Accra

Slide 3

Slide 3 text

“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

Slide 4

Slide 4 text

Mobile devices have less resources; Memory, battery life,CPU, etc. hence so many trade-offs during development. What are your trade-offs? Accra

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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)

Slide 8

Slide 8 text

A deeper look into common Mobile Device Resource * Memory * Memory Footprints * Garbage Collection

Slide 9

Slide 9 text

DEMO ON MEMORY FOOTPRINT

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Detecting Blocking Task - StrictMode * Detect and logs potential issues of files and network operations.

Slide 12

Slide 12 text

Strategies for Maintaining Responsiveness - Spawn a new thread * Thread/Looper/Handler * HandlerThread * AsyncTask * Thread pools * Native threads

Slide 13

Slide 13 text

DEMO ON NETWORK & FILE OPERATIONS

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

Oliver Mensah, Agro Innova @Oliver_Mensah Location Thank you!

Slide 16

Slide 16 text

Q&A Location