We know reflection or enum are contentious topics, but do they cause *real* performance problems? Let's see!
Performance mythsin AndroidJavier Gamarra / @nhpatt
View Slide
“Why is this important?”
“Please try again soon!”
Performance is anotherfeature 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
GPU Overdraw
Leak Canary
Hierarchy view
Allocation tracker
Traceview
GPU profiler
HProf
systrace
Battery historian
External tools (nimbledroid…)
Use an old device
Be pragmatic
FACTSorMYTHS?
“things the communityis very passionate about”
lots of things...
iosched
“Own” methodsWithout games and not counting library methods
Methods in mostpopular apps-facebook-facebook chat-twitter
1 DATABASES
Record actual performance“Write” Espresso testsRewrite database “layer”Measure time to finishCheck 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 beaccessed on the threadthey were created”
0’0%
ORM performancedoesn’t matter
Do NOT choose an ORMbecause performance
I'll take something 10-20% slowerthat offers better APIs for thevery reason that you'll never getclose to the limits -- Jake
2DI FRAMEWORKS
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 5times [slower] compared to Dagger”
Synthetic app with 5455 injections:Roboguice: 3923 msDagger1: 154msDagger2: 62 msDirectamente: 39ms
3REACTIVELIBRARIES
about lazyness
Shakespeare playsscrabble
Range
When Not to Use RxJavaSmall, constant datasetsExpensive objectsMany flatmaps
= 8x slower to iterate
4PART04MICRO OPTIMIZATIONS
Enums-- like 285 bytes lost
“If you use integer constants instead ofenums in your Android app you are afool” --Jake Wharton
We use enums regularly becausethey are safer than Strings or intsand their performance downsidesare minimal --instagram
OnClickListeners?
How much costs to iteratebetween 1M likes?
300 ms30 MB
JSON parsingNetwork requests
LASTWORDS
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 slowbut does it matter to you?
?QUESTIONS?@nhpatt / twittergmailgithub...
THANKS
References● Awesome list● Google+ community● High performanceprogramming book● Performance TestingTools● Speed up your app
“If you care more about performancethan correctness why using a computerat all?”I can give you the wrong answer fasterthan any machine ;) -- Mario Fusco