74
Performance myths in Android Javier Gamarra / @nhpatt

Performance myths in android

Embed Size (px)

Citation preview

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

GPU Overdraw

Leak Canary

Hierarchy view

Allocation tracker

Traceview

Traceview

GPU profiler

HProf

systrace

Battery historian

External tools (nimbledroid…)

Use an old device

Be pragmatic

FACTSor

MYTHS?

“things the communityis very passionate about”

lots of things...

iosched

“Own” methods

Without games and not counting library methods

Methods in most popular apps

-facebook-facebook chat-twitter

1 DATABASES

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”

0’0%

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

2

DI 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?

“Roboguice would (...) be (...) a mere 5 times [slower] compared to Dagger”

3

REACTIVE LIBRARIES

<BS> about lazyness

Shakespeare plays scrabble

Range

= 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?

300 ms

30 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 slow but does it matter to you?

?QUESTIONS?@nhpatt / twitter

gmailgithub...

THANKS

“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