understanding, debugging and fixing power bugs

Post on 20-Jun-2015

4.299 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

The talk covers how to understand and debug your app's power consumption and covers optimization techniques that can be used to create efficient apps, that customers love!

TRANSCRIPT

Understanding, Debugging and Fixing

Power Bugs

Aditya & Satyam

Power Bugs

Apps are to blame the most for bad battery life

Power Bugs

• Bad coding patterns cause power bugs

• Specific behaviors of the Android Platform

• App inter-dependencies!

• Special Attention must be paid to optimize for power!

Users Hate Power Bugs

Understanding Common Power Bugs

Common Power Bugs 1. Not Sleeping Properly

Common Power Bugs 2. Un-necessary Animations

Common Power Bugs 3. Updating the Screen

Common Power Bugs 4. Handling Display-Off

Common Power Bugs 5. Waking up to notifications

More Types Of Power Bugs

• Registering for un-necessary events

• Waking up the system causes everyone to be woken up

• Register for “active” notifications (instead of passive ones)

• Handset-specific problems

Best Practices(or how to avoid the dreaded battery drain)

Power Consumption is Complex and Inter-dependent among components

Jeff Sharkey at Google IO

Best Practices - Network

• prefetch data

– to avoid switching states frequently, try and read as much data as possible

– trade-off between too much pre-fetch and battery drain

– google recommends pre-fetching data that you will initiate in the next 2 to 5 minutes, and in the order of 1-5 MB size

• batch data

– do data send/receive in batches rather than on-demand

– eg: batch analytics information, rather than sending them as they are collected

Best Practices - Network

• using inexact timers

– AlarmManager.setInexactRepeating()

– use ELAPSED_REALTIME instead of ELAPSED_REALTIME_WAKEUP

• detect network connection

– avoid connection attempts if no network is active

• avoid polling and use GCM when possible

– avoids multiple connections

– reduces the number of device state changes

Best Practices - Screen

• color matters!

– esp on OLED screens

– darker the color, lesser the consumption

• brightness levels have more impact

– refer to - http://stackoverflow.com/questions/5032588/cant-apply-system-screen-brightness-programmatically-in-android

Best Practices - Screen

• programmatically reduce brightness if its suits your app/activity

• Use “night mode” for reading Apps

• Think about your color scheme

Best Practices - CPU

• wakelocks are your friend, but your users worst nightmare!

• use them only if really needed and ensure they are removed as soon as possible

• Use ‘android:keepScreenOn’ property in your manifest instead of doing it programmatically

Best Practices - CPU

• if possible, spread out your computationally intensive job

• gpu typically consumes more power than cpu

– avoid floating point math where possible

• use algorithms that consume less CPU cycle

– O(n log n) vs O(n 2) algorithms

Identifying power bugs with little eye

Demo

Optimized Apps = Better User Experience

Thank You

www.littleeye.co

aditya@littleeye.cosatyam@littleeye.co

top related