Android Performance and Profiling Tips

Post on 13-Apr-2017

427 views 2 download

Transcript of Android Performance and Profiling Tips

Chris Ripple | Program Manager

Performance & Profiling Tips

Session OverviewProfiling / Sampling

Method profiling

View Heap

Memory Allocations

Performance / Profiling Tools

Android SDK DDMS

Android Studio

History

AndroidBest

PracticesAndroid

JavaAndroidLayout AsyncTask

About the App

Team Xuni12 Developers in 6 Countries

Pittsburgh Shanghai

Sprint Planning App

2x sprints a day…

…in 30 mins…

…anywhere.

Slow scrolling

Slow animation

App crashes

GOALS: To plan… BUGS:

Performance & Profiling Tools First, identify the problem.

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

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.

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.

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

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

Best Practices

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)

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)

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

AsyncTask: How

onPreExecute

doInBackground

onPostExecute

onProgressUpdate

UI Thread

UI Thread

UI Thread

SummaryProfiling / Sampling

Method profiling

View Heap

Memory Allocations

Performance / Profiling Tools

Android SDK DDMS

Android Studio

History

AndroidBest

PracticesAndroid

JavaAndroidLayout AsyncTask

More Resources

Read Android SDK developer.android.com

Follow Official Android Blog android-developers.blogspot.com

Follow GrapeCity Xuni Blog goxuni.com/blog

Questions?