Performance myths
in Android
Javier Gamarra / @nhpatt
Slide 2
Slide 2 text
“Why is this important?”
Slide 3
Slide 3 text
“Please try again soon!”
Slide 4
Slide 4 text
Performance is another
feature of your app like
… login
Slide 5
Slide 5 text
Performance is
… CPU
… memory
… network
… battery
… smoothness
Slide 6
Slide 6 text
Always measure first
Slide 7
Slide 7 text
Tools!
--using the right tool for the job
Slide 8
Slide 8 text
Performance monitors
Slide 9
Slide 9 text
Android device monitor
Slide 10
Slide 10 text
GPU Overdraw
Slide 11
Slide 11 text
Leak Canary
Slide 12
Slide 12 text
Hierarchy view
Slide 13
Slide 13 text
Allocation tracker
Slide 14
Slide 14 text
Traceview
Slide 15
Slide 15 text
Traceview
Slide 16
Slide 16 text
GPU profiler
Slide 17
Slide 17 text
HProf
Slide 18
Slide 18 text
systrace
Slide 19
Slide 19 text
Battery historian
Slide 20
Slide 20 text
External tools (nimbledroid…)
Slide 21
Slide 21 text
Use an old device
Slide 22
Slide 22 text
Be pragmatic
Slide 23
Slide 23 text
FACTS
or
MYTHS?
Slide 24
Slide 24 text
“things the community
is very passionate about”
Slide 25
Slide 25 text
lots of things...
Slide 26
Slide 26 text
iosched
Slide 27
Slide 27 text
“Own” methods
Without games and not counting library methods
Slide 28
Slide 28 text
Methods in most
popular apps
-facebook
-facebook chat
-twitter
Slide 29
Slide 29 text
1 DATABASES
Slide 30
Slide 30 text
No content
Slide 31
Slide 31 text
No content
Slide 32
Slide 32 text
Record actual performance
“Write” Espresso tests
Rewrite database “layer”
Measure time to finish
Check allocation tracker
Check traceview
Slide 33
Slide 33 text
Use Case 1 (first use)
4,18MB
78,8% parsing
2,5 TV seconds
8,8 seconds
Slide 34
Slide 34 text
Use case 2 (remotely)
4,23MB
13% drawing
1,64 TV seconds
4,28 seconds
Slide 35
Slide 35 text
Use case 3 (normal)
4,83MB
13% drawing
2,54 TV seconds
4,82 seconds
Slide 36
Slide 36 text
No content
Slide 37
Slide 37 text
“Realm objects can only be
accessed on the thread
they were created”
Slide 38
Slide 38 text
No content
Slide 39
Slide 39 text
0’0%
Slide 40
Slide 40 text
No content
Slide 41
Slide 41 text
ORM performance
doesn’t matter
Slide 42
Slide 42 text
Do NOT choose an ORM
because performance
Slide 43
Slide 43 text
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
Slide 44
Slide 44 text
2
DI FRAMEWORKS
Slide 45
Slide 45 text
How slow is reflection?
Slide 46
Slide 46 text
... pretty much when done a lot
700 ms to NYTimes
660 ms to photobucket
...like JSON/XML parsing
Slide 47
Slide 47 text
And in DI frameworks?
Slide 48
Slide 48 text
Synthetic app with 5455 injections:
Roboguice: 3923 ms
Dagger1: 154ms
Dagger2: 62 ms
Slide 49
Slide 49 text
“Roboguice would (...) be (...) a mere 5
times [slower] compared to Dagger”
Slide 50
Slide 50 text
Synthetic app with 5455 injections:
Roboguice: 3923 ms
Dagger1: 154ms
Dagger2: 62 ms
Directamente: 39ms
Slide 51
Slide 51 text
3
REACTIVE
LIBRARIES
Slide 52
Slide 52 text
about lazyness
Slide 53
Slide 53 text
Shakespeare plays
scrabble
Slide 54
Slide 54 text
Range
Slide 55
Slide 55 text
When Not to Use RxJava
Small, constant datasets
Expensive objects
Many flatmaps
Slide 56
Slide 56 text
= 8x slower to iterate
Slide 57
Slide 57 text
4
PART04
MICRO OPTIMIZATIONS
Slide 58
Slide 58 text
Enums
-- like 285 bytes lost
Slide 59
Slide 59 text
“If you use integer constants instead of
enums in your Android app you are a
fool” --Jake Wharton
Slide 60
Slide 60 text
We use enums regularly because
they are safer than Strings or ints
and their performance downsides
are minimal --instagram
Slide 61
Slide 61 text
OnClickListeners?
Slide 62
Slide 62 text
How much costs to iterate
between 1M likes?
Slide 63
Slide 63 text
300 ms
30 MB
Slide 64
Slide 64 text
JSON parsing
Network requests
Slide 65
Slide 65 text
LAST
WORDS
Slide 66
Slide 66 text
Things I like/UI
● Flat layout hierarchy
● Merge tags
● Optimized bitmaps
● Inexistent alpha
Slide 67
Slide 67 text
Things I like/code
● WeakReferences
● Caches
● FlatBuffers
● Developer Efficiency
Slide 68
Slide 68 text
“Do the simple thing first
… and optimize what matters”
Slide 69
Slide 69 text
Ok, dagger/rx/ORM is slow
but does it matter to you?
Slide 70
Slide 70 text
?
QUESTIONS?
@nhpatt / twitter
gmail
github
...
Slide 71
Slide 71 text
THANKS
Slide 72
Slide 72 text
References
● Awesome list
● Google+ community
● High performance
programming book
● Performance Testing
Tools
● Speed up your app
Slide 73
Slide 73 text
“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
Slide 74
Slide 74 text
Performance myths
in Android
Javier Gamarra / @nhpatt