Slide 1

Slide 1 text

Speed up your app Udi Cohen

Slide 2

Slide 2 text

MEASURE SLOW DEVICE TRADE-OFFS The Rules: ALWAYS USE CONSIDER

Slide 3

Slide 3 text

Systrace

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

EXAMPLE SYSTRACE

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Frame >16ms

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Traceview

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

NAME List of all executed methods

Slide 17

Slide 17 text

INCLUSIVE CPU TIME Time spent on the method and all methods it calls

Slide 18

Slide 18 text

EXCLUSIVE CPU TIME Time spent just in the method itself

Slide 19

Slide 19 text

INC/EXC REAL TIME Actual time the method took from start to finish

Slide 20

Slide 20 text

METHOD CALLS Number of times the method was called and how long each call took (avg.)

Slide 21

Slide 21 text

EXAMPLE TRACEVIEW

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

??

Slide 27

Slide 27 text

Memory Profiling

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

GC

Slide 30

Slide 30 text

Call GC Dump Heap Alloc Tracker

Slide 31

Slide 31 text

HEAP SNAPSHOT

Slide 32

Slide 32 text

Eclipse MAT

Slide 33

Slide 33 text

Call GC Dump Heap Alloc Tracker

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Memory Tips Bitmap’s pixel format HashMap vs. ArrayMap / Sparse*Array Context Awareness

Slide 36

Slide 36 text

LeakCanary

Slide 37

Slide 37 text

GPU Profiling

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

< <=

Slide 44

Slide 44 text

adb shell dumpsys gfxinfo <=

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

Hierarchy Viewer

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

Render times •Measure, Layout and Draw. •For the view and its children

Slide 49

Slide 49 text

Measure Performance Indicators Layout Draw Green: view is in the faster 50% Yellow: view is in the slower 50% Red: view is the slowest in the tree

Slide 50

Slide 50 text

Overdraw

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

1x Overdraw 2x Overdraw 3x Overdraw 4x Overdraw+ No Overdraw

Slide 53

Slide 53 text

Too much..

Slide 54

Slide 54 text

Alpha

Slide 55

Slide 55 text

setAlpha() ALPHA The direct approach

Slide 56

Slide 56 text

setAlpha() ALPHA The complex approach

Slide 57

Slide 57 text

Alpha Tips TextView setTextColor() instead of setAlpha() ImageView setImageAlpha() instead of setAlpha() Custom Views Handle alpha yourself by overriding onSetAlpha() Override hasOverlappingRendering()

Slide 58

Slide 58 text

Hardware Acceleration

Slide 59

Slide 59 text

Using Hardware Layers OR

Slide 60

Slide 60 text

EXAMPLE HW LAYERS

Slide 61

Slide 61 text

View Pager ! Parallax effect for the pages background ! Views in the page are moved as we scroll pages

Slide 62

Slide 62 text

Enabling “Show hardware layers updates”

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

Small hack to disable HW layers for ViewPager pages

Slide 65

Slide 65 text

More

Slide 66

Slide 66 text

More Resources Android Performance Patterns playlist on YouTube My blog: http://www.udinic.com Android Performance Patterns Google+ community (#PerfMatters)

Slide 67

Slide 67 text

Thank you! @udinic +UdiCohen www.udinic.com Udi Cohen