android talks #05 - ui optimization of android applications

16
UI optimization of android applications Dino Kovač

Upload: infinum-ltd

Post on 20-Aug-2015

466 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Android Talks #05 - UI optimization of Android applications

UI optimization of android applications

Dino Kovač

Page 2: Android Talks #05 - UI optimization of Android applications

Rules of optimization

1.Don’t.!

2.Don’t… yet.!

3.Profile before optimizing!

Page 3: Android Talks #05 - UI optimization of Android applications

–Donald Knuth

“Premature optimization is the root of all evil.”

Page 4: Android Talks #05 - UI optimization of Android applications

Tools• Hierarchy Viewer!

• “Show GPU Overdraw” (Developer options, android 4.2+)

Page 5: Android Talks #05 - UI optimization of Android applications

Example app• One relevant activity!

• Two lists!

• A compound view as the right list item

Page 6: Android Talks #05 - UI optimization of Android applications

View tree

Page 7: Android Talks #05 - UI optimization of Android applications

How android draws views1. measure pass - each view stores it’s

measurements!

2. layout pass - each view positions it’s children!

3. draw pass - each view draws itself

Page 8: Android Talks #05 - UI optimization of Android applications

Focus of optimization• Flattening layout hierarchy!

• Minimizing overdraw

Page 9: Android Talks #05 - UI optimization of Android applications

Layout simplification

Page 10: Android Talks #05 - UI optimization of Android applications

<merge />

Page 11: Android Talks #05 - UI optimization of Android applications

<merge />

Page 12: Android Talks #05 - UI optimization of Android applications

Overdraw

• Pixels get drawn more than once!

• blue(2), green(3), light red(4), dark red(5)!

• mostly multiple backgrounds

Page 13: Android Talks #05 - UI optimization of Android applications

Tweaking the selector

Page 14: Android Talks #05 - UI optimization of Android applications

Overdraw before/after

Page 15: Android Talks #05 - UI optimization of Android applications

Some numbers

Hierarchy depth

Total views Measure Layout Draw Total

Before 9 76 0.354 1.7792 3.3624 5.4956

After 8 52 0.3402 1.0984 2.7098 4.1484

Page 16: Android Talks #05 - UI optimization of Android applications

References• http://c2.com/cgi/wiki?RulesOfOptimization!

• http://www.youtube.com/watch?v=URyoiAt8098!

• http://www.youtube.com/watch?v=-FUw8HMbmBQ!

• http://android-developers.blogspot.com/2009/03/android-layout-tricks-3-optimize-by.html!

• http://developer.android.com/training/improving-layouts/optimizing-layout.html!

• https://github.com/reisub/android_uioptimizationexample