writing energy efficient code - apple inc. · 2016-07-08 · writing energy efficient code part 2...

166
© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. #WWDC14 Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS

Upload: others

Post on 04-Jun-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

#WWDC14

Writing Energy Efficient CodePart 2

Session 712 Albert Liu iOS Software Power Engineer

Core OS

Page 2: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about
Page 3: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about
Page 4: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Agenda

Quick Recap

Energy Efficient Networking

Measuring Impact

Sleep

Final Thoughts

Page 5: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Quick Recap

Page 6: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy 101Minimizing overhead cost

Time

Pow

er

Idle power

Dynamic cost

Fixed cost

Intermediate statesResource costYour work

Page 7: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Single-Threaded Multi-Threaded

Energy 101Trading power for energy

Time

Pow

er

Resource costYour work

Page 8: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Reducing Energy UseWhat it comes down to…

Do it never

Do it at a better time

Do it more efficiently

Do it less

Page 9: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient CodingOptimizing CPU usage

Page 10: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient CodingOptimizing CPU usage

Do it never

Page 11: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient CodingOptimizing CPU usage

Do it never• Stop unnecessary work on app transitions

Page 12: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient CodingOptimizing CPU usage

Do it never• Stop unnecessary work on app transitions

Do it at a better time

Page 13: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient CodingOptimizing CPU usage

Do it never• Stop unnecessary work on app transitions

Do it at a better time• Scheduling with NSBackgroundActivityScheduler / NSURLSession

Page 14: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient CodingOptimizing CPU usage

Do it never• Stop unnecessary work on app transitions

Do it at a better time• Scheduling with NSBackgroundActivityScheduler / NSURLSession

Do it more efficiently

Page 15: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient CodingOptimizing CPU usage

Do it never• Stop unnecessary work on app transitions

Do it at a better time• Scheduling with NSBackgroundActivityScheduler / NSURLSession

Do it more efficiently• Set appropriate QoS work priorities

Page 16: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient CodingOptimizing CPU usage

Do it never• Stop unnecessary work on app transitions

Do it at a better time• Scheduling with NSBackgroundActivityScheduler / NSURLSession

Do it more efficiently• Set appropriate QoS work priorities

Do it less

Page 17: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient CodingOptimizing CPU usage

Do it never• Stop unnecessary work on app transitions

Do it at a better time• Scheduling with NSBackgroundActivityScheduler / NSURLSession

Do it more efficiently• Set appropriate QoS work priorities

Do it less• Coalesce timers => let CPU idle

Page 18: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

CPU MonitorRunaway background usage

New in iOS 8

Background applications • Termination when runaway usage is detected

• EXC_RESOURCE : CPU_FATAL Crash log

Page 19: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

CPU MonitorRunaway background usage

Page 20: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

CPU MonitorRunaway background usage

Page 21: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

CPU MonitorRunaway background usage

Page 22: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient CodingGraphics and Animations

Page 23: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient CodingGraphics and Animations

Avoid extraneous screen updates

Page 24: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient CodingGraphics and Animations

Avoid extraneous screen updates

Review blur effect usage • Reduce frame changes behind blurs

Page 25: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Agenda

Quick Recap

Energy Efficient Networking

Measuring Impact

Sleep

Final Thoughts

Page 26: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient Networking

Page 27: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Web Server Application

Requirements • Sync data to server

Page 28: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Web Server Application

Current solution • Sync data as it comes

Page 29: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Web Server Application

Current solution • Sync data as it comes

Page 30: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Network EnergyOverhead cost

Data syncs

Time

Pow

er

Page 31: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Network EnergyOverhead cost

Radio costData syncs

Time

Pow

er

Dynamic cost

Overhead cost

Page 32: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Network EnergyWeb browsing

Page 33: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Network EnergyWeb browsing

iPhone 5S • Wifi—10 hours

• 3G—8 hours

Page 34: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Network EnergyAll things are NOT created equal

Page 35: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Network EnergyAll things are NOT created equal

Cellular vs. Wi-Fi

Signal conditions

Network throughput

Page 36: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Webserver Application

Current solution • Buffer data before syncing

Page 37: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Webserver Application

Current solution • Buffer data before syncing

Page 38: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Network Energy

Radio costData syncs

Time

Pow

er

Page 39: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Network Energy

Radio costData syncs

Time

Pow

er

Page 40: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient NetworkingConcepts to remember

Page 41: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient NetworkingConcepts to remember

Doing it more efficiently• Coalesce Transactions

Page 42: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient NetworkingConcepts to remember

Doing it more efficiently• Coalesce Transactions

Doing it less/never• Cut down Transfers

Page 43: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Cut Down/TransfersDoing it never/less

Page 44: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Cut Down/TransfersDoing it never/less

Reduce data sizes • Reduce media quality

• Compress your data

Page 45: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Cut Down/TransfersDoing it never/less

Reduce data sizes • Reduce media quality

• Compress your data

Avoid redundant transfers• Caching

• Resumable transactions

Page 46: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Cut Down/TransfersDoing it never/less

Reduce data sizes • Reduce media quality

• Compress your data

Avoid redundant transfers• Caching

• Resumable transactions

Handle errors• Timeout

• Retry policies

Page 47: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient NetworkingConcepts to remember

Doing it more efficiently • Coalesce Transactions

Doing it less/never • Cut down Transfers

Doing it at a better time • Consider Tolerance

Page 48: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Consider ToleranceDoing it at a better time

Understand requirements • When is it needed?

Consider • Technology used

• Network conditions

Page 49: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Webserver Application

Current solution • Buffer data before syncing

Page 50: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Webserver Application

Current solution • Buffer data before syncing

• Check data before buffer

Page 51: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Webserver Application

Current solution • Buffer data before syncing

• Check data before buffer

Page 52: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Webserver Application

Current solution • Buffer data before syncing

• Check data before buffer

• Sync on good signal conditions

Page 53: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Webserver Application

Current solution • Buffer data before syncing

• Check data before buffer

• Sync on good signal conditions

Page 54: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Webserver Application

Current solution • Buffer data before syncing

• Check data before buffer

• Sync on good signal conditions

Page 55: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NSURLSessionNetworking API

Page 56: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NSURLSessionNetworking API

Pause/Resume

Page 57: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NSURLSessionNetworking API

Pause/Resume

Cache per session

Page 58: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NSURLSessionNetworking API

Pause/Resume

Cache per session

Background sessions

Page 59: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NSURLSessionNetworking API

Pause/Resume

Cache per session

Background sessions• Out of process transactions

Page 60: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NSURLSessionNetworking API

Pause/Resume

Cache per session

Background sessions• Out of process transactions

• Throughput monitoring

Page 61: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NSURLSessionNetworking API

Pause/Resume

Cache per session

Background sessions• Out of process transactions

• Throughput monitoring

• Automatic retries

Page 62: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NSURLSessionDiscretionary tasks

Page 63: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NSURLSessionDiscretionary tasks

Available for background sessions

Page 64: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NSURLSessionDiscretionary tasks

Available for background sessions

Power optimal system scheduling

Page 65: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NSURLSessionDiscretionary tasks

Available for background sessions

Power optimal system scheduling

Adjustable scheduling window

Page 66: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NSURLSessionDiscretionary tasks

Available for background sessions

Power optimal system scheduling

Adjustable scheduling window• configuration.timeoutIntervalForResource // should be > 12 hours

Page 67: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NSURLSessionDiscretionary tasks

Available for background sessions

Power optimal system scheduling

Adjustable scheduling window• configuration.timeoutIntervalForResource // should be > 12 hours

• Error will be thrown if conditions are not met

Page 68: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NSURLSession

NSURLSessionConfiguration *config = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@“com.apple.App.UserRestore”]; [config setAllowsCellularAccess:NO]; [config setDiscretionary:YES]; config.timeoutIntervalForResource = 18 * 60 * 60; !

NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil]; !

NSURL *url = [NSURL URLWithString:@“http://www.foo.com/interesting_thing”]; NSURLSessionTask *task = [session downloadTaskWithURL:url]; [task resume];

Page 69: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NSURLSession

NSURLSessionConfiguration *config = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@“com.apple.App.UserRestore”]; [config setAllowsCellularAccess:NO]; [config setDiscretionary:YES]; config.timeoutIntervalForResource = 18 * 60 * 60; !

NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil]; !

NSURL *url = [NSURL URLWithString:@“http://www.foo.com/interesting_thing”]; NSURLSessionTask *task = [session downloadTaskWithURL:url]; [task resume];

Page 70: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NSURLSession

NSURLSessionConfiguration *config = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@“com.apple.App.UserRestore”]; [config setAllowsCellularAccess:NO]; [config setDiscretionary:YES]; config.timeoutIntervalForResource = 18 * 60 * 60; !

NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil]; !

NSURL *url = [NSURL URLWithString:@“http://www.foo.com/interesting_thing”]; NSURLSessionTask *task = [session downloadTaskWithURL:url]; [task resume];

Page 71: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient NetworkingConcepts to remember

Doing it more efficiently • Coalesce Transactions

Doing it less/never • Cut down Transfers

Doing it at a better time • Consider Tolerance

Page 72: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Agenda

Quick Recap

Energy Efficient Networking

Measuring Impact

Sleep

Final Thoughts

Page 73: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Measuring Impact

Page 74: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Xcode

Page 75: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Xcode

Page 76: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Diagnostics

Page 77: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Diagnostics

Page 78: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Diagnostics

Page 79: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Diagnostics

Page 80: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Diagnostics

Page 81: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Diagnostics

Page 82: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

DemoEnergy diagnostics

Page 83: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Agenda

Quick Recap

Energy Efficient Networking

Measuring Impact

Sleep

Final Thoughts

Page 84: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Sleep

Page 85: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

“To sleep is to prepare for the longer journey ahead…”

Page 86: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

SleepLet the device sleep

Page 87: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

SleepLet the device sleep

Battery life depends on sleep

Page 88: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

SleepLet the device sleep

Battery life depends on sleep

iPhone 5S

Page 89: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

SleepLet the device sleep

Battery life depends on sleep

iPhone 5S• Web browsing—about 8 to 10 hours

Page 90: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

SleepLet the device sleep

Battery life depends on sleep

iPhone 5S• Web browsing—about 8 to 10 hours

• Audio—about 40 hours

Page 91: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

SleepLet the device sleep

Battery life depends on sleep

iPhone 5S• Web browsing—about 8 to 10 hours

• Audio—about 40 hours

• Standby—about 250 hours

Page 92: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about
Page 93: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Voice Over IP

Bluetooth

Location

Networking

Notifications

Page 94: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Device wakesHigh overhead cost

Overhead costDevice wakes

Time

Pow

er

Page 95: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about
Page 96: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about
Page 97: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

???

Page 98: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Sleep/WakesBackground best practices

Notifications

VoIP

Location

Bluetooth

Page 99: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Notifications

Page 100: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NotificationsLocal/Push Notifications

Page 101: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NotificationsLocal/Push Notifications

Device will wake for • Scheduled Local Notifications

• Receive remote Push Notifications

Page 102: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

NotificationsLocal/Push Notifications

Device will wake for • Scheduled Local Notifications

• Receive remote Push Notifications

Set Push Notification priority • 10—Delivered immediately

• 5—Delivered at power conservative time

Page 103: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

VoIP

Page 104: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

VoIP

Persistent connection • Periodic keep-alive packets

• Device wakes

• Code complexity

VoIP wakes

Page 105: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

VoIPPushKit framework

Leverages Apple Push Notification Service • No need to maintain persistent connection

VoIP Push Notifications • App Runtime to process the pushes

• App Relaunched if terminated

• Include up to 4k payload

Page 106: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

VoIPApplication adoption

#import <PushKit/PushKit.h>

!

- (void) voipRegistration {

PKPushRegistry * voipRegistry = [PKPushRegistry alloc] initWithQueue: dispatch_get_main_queue()];

voipRegistry.delegate = self;

voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP]; // register

}

Page 107: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

VoIPApplication adoption

#import <PushKit/PushKit.h>

!

- (void) voipRegistration {

PKPushRegistry * voipRegistry = [PKPushRegistry alloc] initWithQueue: dispatch_get_main_queue()];

voipRegistry.delegate = self;

voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP]; // register

}

Page 108: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

VoIPApplication adoption

#import <PushKit/PushKit.h>

!

- (void) voipRegistration {

PKPushRegistry * voipRegistry = [PKPushRegistry alloc] initWithQueue: dispatch_get_main_queue()];

voipRegistry.delegate = self;

voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP]; // register

}

Page 109: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

VoIPApplication adoption

- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type {

// register voip push token with server

}

!

- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type {

// received push

}

Page 110: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

VoIPApplication adoption

- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type {

// register voip push token with server

}

!

- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type {

// received push

}

Page 111: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

VoIPApplication adoption

- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type {

// register voip push token with server

}

!

- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type {

// received push

}

Page 112: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

VoIPServer side changes

Request VoIP Push Certificate

Send Push with VoIP Certificate • Receiving device requires iOS 8

Page 113: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Location

Page 114: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

LocationContinuous location updates

Page 115: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

LocationContinuous location updates

[locationManager startUpdatingLocation]

!

Prevent device sleep

Accuracy makes a difference

Page 116: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient LocationDeferred location updates

Page 117: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient LocationDeferred location updates

[locationManager allowDeferredLocationUpdatesUntilTraveled: timeout:]

!

Available for GPS level accuracy

Data buffered on location hardware

Example • Run tracking app

Page 118: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient LocationSignificant location change

Page 119: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient LocationSignificant location change

[locationManager startMonitoringSignificantLocationChanges]

!

Location data with filters • Distance—Over 500 meters

• Time—Over 5 minutes

Example • Weather app

Page 120: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient LocationRegion monitoring

Page 121: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Energy Efficient LocationRegion monitoring

[locationManager startMonitoringForRegion:(CLRegion *)]

!

Application is notified on • Entrance into region

• Exit out of region

Example • Museum app

Page 122: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Stop Location Updates

Page 123: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

LocationRun tracking app

Requirements • Keep track of the route

• Update coupons when close to stores

Page 124: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

LocationRun tracking app

Current solution • Continuous location updates

Page 125: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

LocationRun tracking app

Current solution • Continuous location updates

Page 126: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

LocationRun tracking app

Current solution • Continuous location updates

COUPON

Page 127: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

LocationRun tracking app

Energy efficient solution • Deferred location updates

• Region monitoring

Page 128: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

LocationRun tracking app

Energy efficient solution • Deferred location updates

• Region monitoring

Page 129: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

LocationRun tracking app

Energy efficient solution • Deferred location updates

• Region monitoring

Page 130: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

LocationRun tracking app

Energy efficient solution • Deferred location updates

• Region monitoring COUPON

Page 131: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

LocationEnergy efficient APIs

Deferred location updates

Significant location change

Region monitoring

iBeacons

AutoPause

Significant locations visited

Page 132: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

LocationEnergy efficient APIs

Deferred location updates

Significant location change

Region monitoring

iBeacons

AutoPause

Significant locations visited

Page 133: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Bluetooth

Page 134: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

BluetoothInteracting with accessories

Page 135: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Data transfer • Device wake for application

BluetoothInteracting with accessories

Page 136: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Data transfer • Device wake for application

BluetoothInteracting with accessories

Overhead costDevice wakes

Time

Pow

er

Page 137: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

BluetoothRun tracking app

Page 138: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

BluetoothStreaming

Page 139: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

BluetoothStreaming

Fitness DataFitness DataFitness DataFitness DataFitness Data

Page 140: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

BluetoothBuffering

Page 141: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

BluetoothBuffering

Buffer Full!!!

Page 142: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

BluetoothBuffering

Buffer Full!!!

Page 143: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

BluetoothBuffering

Page 144: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Run tracking appOne Step Further

Page 145: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Run tracking appOne Step Further

Page 146: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Run tracking appOne Step Further

Page 147: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Run tracking appOne Step Further

Location data

Page 148: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Run tracking appOne Step Further

Location data

Give me data

Page 149: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Run tracking appOne Step Further

Location data

Give me data

Page 150: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Run tracking appOne Step Further

Page 151: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Coalesce workCut down wakes

Page 152: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Final Thoughts

Page 153: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

“With great power comes great responsibility…”

Page 154: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

SummaryYour turn

Page 155: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

SummaryYour turn

Battery life impacts user experience

Page 156: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

SummaryYour turn

Battery life impacts user experience

Design your apps with the following in mind

Page 157: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

SummaryYour turn

Battery life impacts user experience

Design your apps with the following in mind

Do it never/less

Page 158: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

SummaryYour turn

Battery life impacts user experience

Design your apps with the following in mind

Do it never/less

Do it more efficiently

Page 159: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

SummaryYour turn

Battery life impacts user experience

Design your apps with the following in mind

Do it never/less

Do it more efficiently

Do it at a better time

Page 160: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

SummaryYour turn

Battery life impacts user experience

Design your apps with the following in mind

Do it never/less

Do it more efficiently

Do it at a better time

Be a considerate background app

Page 161: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

SummaryYour turn

Battery life impacts user experience

Design your apps with the following in mind

Do it never/less

Do it more efficiently

Do it at a better time

Be a considerate background app

Coalesce work

Page 162: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

SummaryYour turn

Battery life impacts user experience

Design your apps with the following in mind

Do it never/less

Do it more efficiently

Do it at a better time

Be a considerate background app

Coalesce work

Cutdown wakes

Page 163: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

More Information

Paul Danbold Core OS Technology Evangelist [email protected]

Jake Behrens Apps Frameworks Evangelist [email protected]

Apple Developer Forums http://devforums.apple.com

Page 164: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Related Sessions

• Advanced Graphics and Animations for iOS Apps Russian Hill Tuesday 10:15AM

• What’s New in Core Location Marina Tuesday 2:00PM

• What’s New in Foundation Networking Nob Hill Tuesday 3:15PM

• Improving Your App with Instruments Marina Tuesday 4:30PM

• Writing Energy Efficient Code, Part I Russian Hill Wednesday 10:15AM

• Power, Performance and Diagnostics: What’s New in GCD and XPC

Russian Hill Thursday 2:00PM

Page 165: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about

Labs

• Power and Performance Lab Core OS Lab B Wednesday 2:00PM

• Power and Performance Lab Core OS Lab A Thursday 3:15PM

• Notifications Lab Services Lab B Wednesday 3:15PM

• Instruments Lab Tools Lab B Thursday 9:00AM

• Core Location Lab Core OS Lab B Thursday 12:45PM

• Accessories and I/O Technologies Lab Core OS Lab A Thursday 12:45PM

Page 166: Writing Energy Efficient Code - Apple Inc. · 2016-07-08 · Writing Energy Efficient Code Part 2 Session 712 Albert Liu iOS Software Power Engineer Core OS. Agenda ... • Web browsing—about