Performance: How to build
an app instead of slideshow
by Anton Minashkin
What is a Performance?
Rule #1: Slow != Sluggish
FPS
Frame duration
Skipped frames
FPS (60. Well… Almost)
Frame duration (16.667. Ok, ok, should be like that)
Skipped frames (0. Just shut up. We're all believe in it)
What is a Frame?
So why my app skips frames?
Overdraw
Overdraw
Overdraw
Alpha
Alpha
“Rendering of transparent pixels on
screen, known as alpha rendering, is a
key contributor to overdraw” - Android
Performance Tips
Alpha
Rule #2: If you need a grey color
- use the f****g grey color!
Alpha
This is grey!!
Complex View Hierarchy
Complex View Hierarchy
1. Less or equal 3 View levels (don’t try to
write it with symbols)
2. RelativeLayout instead of nested
LinearLayouts
Complex View Hierarchy
1. ConstraintLayout
2. Merge
Complex View Hierarchy
onLayout() + onMeasure()
onLayout() + onMeasure()
Rule #3: Don’t call it!
onLayout() + onMeasure()
1. Animations
2. Custom Views
GC( ) callsnew Object(); new Object();
new Object(); new Object();
new Object(); new Object();
GC() calls
1. Use object pools
2. Use mappings carefully
3. Know when Android fails
GC() calls
1. Do NOT create anything in onDraw()
2. Cache!
GC() calls
1. Strings & Fonts
2. Use Android collections
GC() calls
Logs:
Log.i(TAG, “User name - “ + name);
GC() calls
Logs:
Log.i(TAG, “User name - “ + name);
Memory Leak!
IO
IO
IO calls are blocking calls. And slow.
And sometime concurrent.
IO
Rule #4: Always do IO in a
background
RecyclerView
RecyclerView
RecyclerView
RecyclerView
RecyclerView
RecyclerView
RecyclerView
RecyclerView
RecyclerView
RecyclerView is not the same as
ListView. And the difference is not about
ViewHolder
RecyclerView
1. Use default implementations
2. Do understand how it works
3. Forget this method -
notifyDataSetChanged()
Rule #5: Google before code
How not to make it worse?
Rule#6: Do not look at code!
Until you know what goes wrong
Statistic
1. Use Developer Console
2. Consider performance issues as
bugs
Debugging
Debugging
Debugging
adb shell dumpsys gfxinfo <PACKAGE_NAME>
Do tests
1. Yes, you can write a test for performance issue
2. Yes, do it
3. Check gfxinfo
Rule#7: Regression matters
Info
To read:
d.android.com/vitals
To watch:
Android Performance Patterns on Youtube
Everything from Chet Haase
To complain (cry):
@AntonMinashkin
anton.minashkin@outlook.com
...any social network

Performance: How to build an app instead of slideshow