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