Performance myths in AndroidJavier Gamarra / @nhpatt
“Why is this important?”
“Please try again soon!”
Performance is another feature of your app like
… login
Performance is… CPU… memory… network… battery… smoothness
Always measure first
Tools!--using the right tool for the job
Performance monitors
Android device monitor
Allocation tracker
Battery historian
External tools (nimbledroid…)
Use an old device
“things the communityis very passionate about”
lots of things...
“Own” methods
Without games and not counting library methods
Methods in most popular apps
-facebook-facebook chat-twitter
Record actual performance“Write” Espresso tests
Rewrite database “layer”Measure time to finish
Check allocation trackerCheck traceview
Use Case 1 (first use)
4,18MB78,8% parsing2,5 TV seconds8,8 seconds
Use case 2 (remotely)
4,23MB13% drawing1,64 TV seconds4,28 seconds
Use case 3 (normal)
4,83MB13% drawing2,54 TV seconds4,82 seconds
“Realm objects can only be accessed on the thread they were created”
ORM performance doesn’t matter
Do NOT choose an ORM because performance
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
How slow is reflection?
... pretty much when done a lot700 ms to NYTimes660 ms to photobucket
...like JSON/XML parsing
And in DI frameworks?
Synthetic app with 5455 injections:Roboguice: 3923 msDagger1: 154msDagger2: 62 ms
“Roboguice would (...) be (...) a mere 5 times [slower] compared to Dagger”
Synthetic app with 5455 injections:Roboguice: 3923 msDagger1: 154msDagger2: 62 msDirectamente: 39ms
3
REACTIVE LIBRARIES
<BS> about lazyness
Shakespeare plays scrabble
When Not to Use RxJavaSmall, constant datasetsExpensive objectsMany flatmaps
= 8x slower to iterate
4PART04
MICRO OPTIMIZATIONS
Enums-- like 285 bytes lost
“If you use integer constants instead of enums in your Android app you are a fool” --Jake Wharton
We use enums regularly because they are safer than Strings or ints and their performance downsides are minimal --instagram
OnClickListeners?
How much costs to iterate between 1M likes?
JSON parsingNetwork requests
Things I like/UI
● Flat layout hierarchy
● Merge tags
● Optimized bitmaps
● Inexistent alpha
Things I like/code
● WeakReferences
● Caches
● FlatBuffers
● Developer Efficiency
“Do the simple thing first… and optimize what matters”
Ok, dagger/rx/ORM is slow but does it matter to you?
?QUESTIONS?@nhpatt / twitter
gmailgithub...
References
● Awesome list● Google+ community● High performance
programming book● Performance Testing
Tools● Speed up your app
“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
Performance myths in AndroidJavier Gamarra / @nhpatt