android performance and profiling tips

19
Chris Ripple | Program Manager Performance & Profiling Tips

Upload: kelley-ricker

Post on 13-Apr-2017

428 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Android Performance and Profiling Tips

Chris Ripple | Program Manager

Performance & Profiling Tips

Page 2: Android Performance and Profiling Tips

Session OverviewProfiling / Sampling

Method profiling

View Heap

Memory Allocations

Performance / Profiling Tools

Android SDK DDMS

Android Studio

History

AndroidBest

PracticesAndroid

JavaAndroidLayout AsyncTask

Page 3: Android Performance and Profiling Tips

About the App

Page 4: Android Performance and Profiling Tips

Team Xuni12 Developers in 6 Countries

Pittsburgh Shanghai

Page 5: Android Performance and Profiling Tips

Sprint Planning App

2x sprints a day…

…in 30 mins…

…anywhere.

Slow scrolling

Slow animation

App crashes

GOALS: To plan… BUGS:

Page 6: Android Performance and Profiling Tips

Performance & Profiling Tools First, identify the problem.

Page 7: Android Performance and Profiling Tips

Profiling What is Profiling?

o Analyzing behavior in runtimeo CPU utilizationo Memory and I/O analysiso Measurement of time and space

Why do we need it?o Avoid guessworko Quickly identify performance pitfalls

Page 8: Android Performance and Profiling Tips

Android Profiling Tools

• Heap view• Memory alloc• Method profiling• Logcat• File explorer• Examine threads• Network traffic

• View hierarchy• Emulate calls• System info

• CPU• GPU• FPS

• Allocation Tracker• Memory monitor• Android Memory Viewer• GPU monitor• CPU monitor• Network monitor

Android SDKDDMS

Jacob Chirayil
Do we know some history about these tools? When they got released? Whey got popular? High level overview on what developer community thinks about these tools?
Vivek
It will now follow from the history slide, so that it can be easily traced in time
Jacob Chirayil
Can we show screen shot of these tools on right side? Just for some visual comparison
Vivek
Yes, screenshots would be good to add
Jacob Chirayil
Don't forget to explain about abbreviation like CPU/GPU and another abbreviated terms used in the presentation, as well as explain the importance/relevance.
Page 9: Android Performance and Profiling Tips

Android Profiling Tools

• Method profiling• Heap view• Memory allocations

• Allocation Tracker• Memory monitor

Android SDKDDMS

Jacob Chirayil
Do we know some history about these tools? When they got released? Whey got popular? High level overview on what developer community thinks about these tools?
Vivek
It will now follow from the history slide, so that it can be easily traced in time
Jacob Chirayil
Can we show screen shot of these tools on right side? Just for some visual comparison
Vivek
Yes, screenshots would be good to add
Jacob Chirayil
Don't forget to explain about abbreviation like CPU/GPU and another abbreviated terms used in the presentation, as well as explain the importance/relevance.
Page 10: Android Performance and Profiling Tips

DDMS Method profiling Sample-based profiling

o Interrupt VM at sampling frequency at collection call stackso Overhead proportional to frequency

Trace-based profilingo Trace entry and exit of every methodo High overhead

Start Record, Perform Action, Stop Record Timeline vs Traceview panel views

Page 11: Android Performance and Profiling Tips

DDMS – Memory tracking

Total available heap space Total space allocated Total space free % Used Total # Objects Object allocation per size

List of all allocations Allocation order Allocation size Class / Stacktrace Thread Id Allocated In

Heap View Allocation Tracker

Page 12: Android Performance and Profiling Tips

Best Practices

Page 13: Android Performance and Profiling Tips

Java Android Best Practices Recycling / Object Pooling Pattern ( Scrolling, Animation, Games) General Caching (Images / resources) Optimized Data Containers (SparseArray vs HashMap) Primitives (Integer vs Float 2x slower) Avoid enums Utilize static / final keywords (static 15%-20% faster) Avoid internal getters / setters (direct field access 3x faster)

Page 14: Android Performance and Profiling Tips

Layout Best Practices RecyclerView (replaces ListView and GridView)

o setHasFixedSizeo Data updates (notifyDataSetChanged)o Layout updates (notifyItemChanged / Inserted / Removed)

<include> tag (easy code reuse of common layouts) <merge> tag (avoid extra ViewGroups on inflation) TextView Compound Drawables (add images to TextView)

Page 15: Android Performance and Profiling Tips

AsyncTask: Why and What

Why use async? Avoid locking main UI Thread

o Lago App crash

What should be async? Network access Image loading Image resizing File access

Page 16: Android Performance and Profiling Tips

AsyncTask: How

onPreExecute

doInBackground

onPostExecute

onProgressUpdate

UI Thread

UI Thread

UI Thread

Page 17: Android Performance and Profiling Tips

SummaryProfiling / Sampling

Method profiling

View Heap

Memory Allocations

Performance / Profiling Tools

Android SDK DDMS

Android Studio

History

AndroidBest

PracticesAndroid

JavaAndroidLayout AsyncTask

Page 18: Android Performance and Profiling Tips

More Resources

Read Android SDK developer.android.com

Follow Official Android Blog android-developers.blogspot.com

Follow GrapeCity Xuni Blog goxuni.com/blog

Page 19: Android Performance and Profiling Tips

Questions?