pref presentation (2)

17

Upload: prachi-patil

Post on 13-Apr-2017

128 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Pref Presentation (2)
Page 2: Pref Presentation (2)

Code level fixes

DDMS tools&

Developer Options

GPU overdraw

Heap dumpAllocation Tracker

Hierarchy ViewerGPU Rendering

Trace Viewer

Optimized Imports

Performance tweaks

Lint Tool

Avoid memory leaks

ImproveCode

Analyse & improve app performance

Smooth, Optimized

app

Optimization

Page 3: Pref Presentation (2)

Avoid Memory leaks

❖ Use Drawables efficiently❖ Broadcast❖ Context related leaks

● Application level context● Activity level context

Page 4: Pref Presentation (2)

Performance Tweaks

❖ Use Static Final to declare Constants.❖ Access variables directly instead of getter/setter for internal

use.❖ Avoid Creating Unnecessary Objects.❖ Use loops efficiently.

Page 5: Pref Presentation (2)

For LoopCode Snippet

Log.i(TAG, "-------------------------------------------------");

Log.i(TAG, "-------Start: FOR loop one");

for (int j = 0; j < mCountList.size(); j++) {

//stuff

}

Log.i(TAG, "-------End: FOR loop one");

Log.i(TAG, "-------Start: FOR loop two");

int count = mCountList.size();

for (int j = 0; j < count; j++) {

//stuff

}

Log.i(TAG, "-------End: FOR loop two");

Log.i(TAG, "-------------------------------------------------");

Page 6: Pref Presentation (2)

Logcat

Page 7: Pref Presentation (2)

Lint Tool

❖ Static code analysis tool that checks your Android project source files for potential bugs and optimization improvements for correctness, security, performance, usability, accessibility, and internationalization.

Page 8: Pref Presentation (2)

Lint Result To run Lint tool Analyze Inspect Code

Page 9: Pref Presentation (2)

DDMS & Developers Options

❖ GPU overdraw❖ GPU Rendering❖ Trace Viewer❖ Hierarchy Viewer❖ Heap dump❖ Allocation Tracker

Page 10: Pref Presentation (2)

GPU Overdraw

Atleast 4X

3X

2X

1X

Debug GPU overdraw:

Lets you see when and where this is happening so you know if it is a problem.

Page 11: Pref Presentation (2)

Buggy Without Overdraw Issue

Example of GPU overdraw

Page 12: Pref Presentation (2)

Profile GPU rendering❖ Blue bar represents the time used

to create and update the View's display lists.

❖ Red bar represents the time spent by Android's 2D renderer issuing commands to OpenGL to draw and redraw display lists.

❖ Orange bar represents the time CPU is waiting for the GPU to finish its work.

Page 13: Pref Presentation (2)

Hierarchy Viewer tool ❖ Allows you to debug and optimize your user interface. ❖ It provides a visual representation of the layout's View hierarchy

(the Layout View) and a magnified inspector of the display (the Pixel Perfect View).

Page 14: Pref Presentation (2)

Systrace tool

❖ It shows where time and CPU cycles are being spent, displaying what each thread and process is doing at any given time.

Page 15: Pref Presentation (2)

Heap Option

❖ To get a little information about what kind of memory your application is using and when, you can view real-time updates to your app's heap in the Device Monitor.

Page 16: Pref Presentation (2)

Allocation Tracker❖ Allocation Tracker records an app's memory allocations and

lists all allocated objects for the profiling cycle with their call stack, size, and allocating code.

❖ Identifying where many similar object types, from roughly the same call stack, are allocated and deallocated over a very short period of time.

❖ Finding the places in your code that may contribute to inefficient memory use.