Top Banner
These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 209 Improving Power Efficiency with App Nap Tony Parker Software Engineer, Cocoa Frameworks
168

Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

May 17, 2019

Download

Documents

buicong
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

These are confidential sessions—please refrain from streaming, blogging, or taking pictures

Session 209

Improving Power Efficiency with App Nap

Tony ParkerSoftware Engineer, Cocoa Frameworks

Page 2: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result
Page 3: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

What is App Nap?

How App Nap Works

App Nap API

Page 4: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

What is App Nap?

Page 5: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

In a World Where…

•Users expect long battery life and high-performance apps

Page 6: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

In a World Where…

•Users expect long battery life and high-performance apps•All apps have about equal access to limited resources

■ CPU time■ Disk I/O■ Energy

Page 7: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

App Nap focuses system resources on the most important user work.

Page 8: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result
Page 9: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Battery Life Responsiveness

Page 10: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Understanding what’s importantApp Nap Heuristics

Page 11: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Understanding what’s importantApp Nap Heuristics

• Foreground vs. background application

Page 12: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Understanding what’s importantApp Nap Heuristics

• Foreground vs. background application•Application type

Page 13: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Understanding what’s importantApp Nap Heuristics

• Foreground vs. background application•Application type• Visibility

Page 14: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Understanding what’s importantApp Nap Heuristics

• Foreground vs. background application•Application type• Visibility•Drawing activity

Page 15: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Understanding what’s importantApp Nap Heuristics

• Foreground vs. background application•Application type• Visibility•Drawing activity•Audio playback

Page 16: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Understanding what’s importantApp Nap Heuristics

• Foreground vs. background application•Application type• Visibility•Drawing activity•Audio playback• Event processing

Page 17: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Understanding what’s importantApp Nap Heuristics

• Foreground vs. background application•Application type• Visibility•Drawing activity•Audio playback• Event processing•Use of existing IOKit power assertion API

Page 18: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Understanding what’s importantApp Nap Heuristics

• Foreground vs. background application•Application type• Visibility•Drawing activity•Audio playback• Event processing•Use of existing IOKit power assertion API•Use of new App Nap API

Page 19: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

DemoApp Nap

Page 20: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

How App Nap Works

Page 21: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

What’s a Watt?

Page 22: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

What’s a Watt?

• Power■ Rate at which energy is consumed■ Measured in watts (W)

Page 23: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

What’s a Watt?

• Power■ Rate at which energy is consumed■ Measured in watts (W)

• Energy■ Stored potential to do work■ Measured in watt-hours (Wh)

Page 24: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

What’s a Watt?

• 50 watt-hour battery• 7 hour battery life

Page 25: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

What’s a Watt?

• 50 watt-hour battery• 7 hour battery life

50 watt-hours7 hours

Page 26: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

What’s a Watt?

• 50 watt-hour battery• 7 hour battery life

50 watt-hours7 hours

≈ 7.1 watts

Page 27: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

What’s a Watt?

• 50 watt-hour battery• 7 hour battery life

50 watt-hours7 hours

≈ 7.1 watts

• Screen

•GPU

•Network

• Storage

•Memory

•CPU

Page 28: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

What’s a Watt?

• 50 watt-hour battery• 7 hour battery life

50 watt-hours7 hours

≈ 7.1 watts

• Screen

•GPU

•Network

• Storage

•Memory

•CPU

• Screen

•GPU

•Network

• Storage

•Memory

•CPU

Page 29: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

What can modern chips do?CPU Power Usage

Page 30: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

What can modern chips do?CPU Power Usage

Idle

Nominal

Turbo

Page 31: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

What can modern chips do?CPU Power Usage

Idle

Nominal

Turbo

0.4 W

Page 32: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

What can modern chips do?CPU Power Usage

Idle

Nominal

Turbo

0.4 W

15 W

Page 33: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

What can modern chips do?CPU Power Usage

Idle

Nominal

Turbo

0.4 W

15 W

25 W

Page 34: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Three key rulesExtending Battery Life

• Stay idle as long as possible•Avoid unnecessary work• Return to idle as quickly as possible

Page 35: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Staying Idle: a Case StudyVisiting apple.com in Safari

Page 36: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

0%

25%

50%

75%

100%

Staying Idle: a Case StudyVisiting apple.com in Safari

CPU

Act

ivity

Page 37: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

0%

25%

50%

75%

100%

Staying Idle: a Case StudyVisiting apple.com in Safari

CPU

Act

ivity

Not idle, highest power

Idle, lowest power

Page 38: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

0%

25%

50%

75%

100%

Staying Idle: a Case StudyVisiting apple.com in Safari

Safari

CPU

Act

ivity

Page 39: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

0%

25%

50%

75%

100%

Staying Idle: a Case StudyVisiting apple.com in Safari

Safari

CPU

Act

ivity

Typing apple.com

Page 40: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

0%

25%

50%

75%

100%

Staying Idle: a Case StudyVisiting apple.com in Safari

Safari

CPU

Act

ivity Downloading Web Page

Typing apple.com

Page 41: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

0%

25%

50%

75%

100%

Staying Idle: a Case StudyVisiting apple.com in Safari

Safari

CPU

Act

ivity Downloading Web Page

Rendering FinishedTyping apple.com

Page 42: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

0%

25%

50%

75%

100%

Staying Idle: a Case StudyVisiting apple.com in Safari

Safari

Eyes Demo

CPU

Act

ivity

Page 43: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

0%

25%

50%

75%

100%

Staying Idle: a Case StudyVisiting apple.com in Safari

Safari

Eyes Demo

CPU

Act

ivity

Polling More Polling Still Polling

Page 44: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

When there is work to doExiting Idle

Page 45: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

When there is work to doExiting Idle

•Network activity

Page 46: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

When there is work to doExiting Idle

•Network activity•Mouse or keyboard input

Page 47: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

When there is work to doExiting Idle

•Network activity•Mouse or keyboard input•Disk I/O

Page 48: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

When there is work to doExiting Idle

•Network activity•Mouse or keyboard input•Disk I/O• Timers

Page 49: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

When there is work to doExiting Idle

•Network activity•Mouse or keyboard input•Disk I/O• Timers

Page 50: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Everything with a relative or absolute deadlineAPI with Timers

Page 51: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Everything with a relative or absolute deadlineAPI with Timers

NSTimer, CFRunLoopTimerRef, DISPATCH_SOURCE_TYPE_TIMER

Page 52: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Everything with a relative or absolute deadlineAPI with Timers

NSTimer, CFRunLoopTimerRef, DISPATCH_SOURCE_TYPE_TIMER

sleep()

Page 53: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Everything with a relative or absolute deadlineAPI with Timers

NSTimer, CFRunLoopTimerRef, DISPATCH_SOURCE_TYPE_TIMER

sleep()

pthread_cond_timedwait(), semaphore_timedwait()

Page 54: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Everything with a relative or absolute deadlineAPI with Timers

NSTimer, CFRunLoopTimerRef, DISPATCH_SOURCE_TYPE_TIMER

sleep()

pthread_cond_timedwait(), semaphore_timedwait()

-[performSelector:withObject:afterDelay:], -[NSRunLoop runUntilDate:]

Page 55: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Everything with a relative or absolute deadlineAPI with Timers

NSTimer, CFRunLoopTimerRef, DISPATCH_SOURCE_TYPE_TIMER

sleep()

pthread_cond_timedwait(), semaphore_timedwait()

-[performSelector:withObject:afterDelay:], -[NSRunLoop runUntilDate:]

… and many more

Page 56: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Reducing the impact of timersExtending Battery Life

Page 57: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Reducing the impact of timersExtending Battery Life

• Timer Coalescing• Timer Rate Limiting

Page 58: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Coalescing

Page 59: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Coalescing

Now 150ms

High

Low

Idle

Pow

er

Page 60: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Coalescing

Now 150ms

High

Low

Idle

Pow

er

T1 T2 T3 T4

Page 61: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Coalescing

Now 150ms

High

Low

Idle

Pow

er

T1 T2 T3 T4

Page 62: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Coalescing

Now 150ms

High

Low

Idle

Pow

er

T1 T2 T3 T4

Page 63: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Coalescing

Now 150ms

High

Low

Idle

Pow

er

T1 T2 T3 T4

Page 64: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Coalescing

Now 150ms

High

Low

Idle

Pow

er

T1 T2 T3 T4

Page 65: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Coalescing

Now 150ms

High

Low

Idle

Pow

er

Saved Energy T1 T2 T3 T4

Page 66: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

After the timer firesSecond Order Effects

• CPU usage

Page 67: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

After the timer firesSecond Order Effects

• CPU usage• Screen

Page 68: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

After the timer firesSecond Order Effects

• CPU usage• Screen•GPU usage

Page 69: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

After the timer firesSecond Order Effects

• CPU usage• Screen•GPU usage•Network

Page 70: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

After the timer firesSecond Order Effects

• CPU usage• Screen•GPU usage•Network• Storage

Page 71: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

After the timer firesSecond Order Effects

• CPU usage• Screen•GPU usage•Network• Storage•Memory

Page 72: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Rate Limiting

Now

High

Idle

Pow

er

1 2 3 4 5 6 7 8 9 10 11 12 seconds

Timer Timer Timer Timer Timer Timer Timer Timer Timer Timer Timer Timer

Page 73: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Rate Limiting

Now

High

Idle

Pow

er

1 2 3 4 5 6 7 8 9 10 11 12 seconds

Timer Timer Timer Timer Timer Timer Timer Timer Timer Timer Timer Timer

Page 74: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Rate Limiting

Now

High

Idle

Pow

er

1 2 3 4 5 6 7 8 9 10 11 12 seconds

Timer Timer Timer Timer Timer Timer Timer Timer Timer Timer Timer Timer

Page 75: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Rate Limiting

Now

High

Idle

Pow

er

1 2 3 4 5 6 7 8 9 10 11 12 seconds

Timer Timer Timer Timer Timer Timer Timer Timer Timer Timer

Page 76: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Rate Limiting

Now

High

Idle

Pow

er

1 2 3 4 5 6 7 8 9 10 11 12 seconds

Timer Timer Timer Timer Timer Timer Timer Timer Timer Timer

Page 77: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Rate Limiting

Now

High

Idle

Pow

er

1 2 3 4 5 6 7 8 9 10 11 12 seconds

Timer Timer Timer Timer Timer Timer Timer

Page 78: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Rate Limiting

Now

High

Idle

Pow

er

1 2 3 4 5 6 7 8 9 10 11 12 seconds

Timer Timer Timer Timer Timer Timer Timer

Page 79: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Rate Limiting

Now

High

Idle

Pow

er

1 2 3 4 5 6 7 8 9 10 11 12 seconds

Timer Timer Timer Timer

Page 80: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Rate Limiting

Now

High

Idle

Pow

er

1 2 3 4 5 6 7 8 9 10 11 12 seconds

Timer Timer Timer Timer

Page 81: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Rate Limiting

Now

High

Idle

Pow

er

1 2 3 4 5 6 7 8 9 10 11 12 seconds

Timer TimerTimerTimer

Page 82: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Rate Limiting

Now

High

Idle

Pow

er

1 2 3 4 5 6 7 8 9 10 11 12 seconds

Timer TimerTimerTimer

Saved Energy Saved Energy Saved Energy

Page 83: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Coalescing and Rate Limiting

• Coalescing delay is on order of 100 ms■ About the same as delay due to normal system load■ Undetectable to user

Page 84: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Coalescing and Rate Limiting

• Coalescing delay is on order of 100 ms■ About the same as delay due to normal system load■ Undetectable to user

• Rate limiting delay is on order of seconds

Page 85: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Coalescing and Rate Limiting

• Coalescing delay is on order of 100 ms■ About the same as delay due to normal system load■ Undetectable to user

• Rate limiting delay is on order of seconds• Timers do not fire early

Page 86: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Coalescing and Rate Limiting

• Coalescing delay is on order of 100 ms■ About the same as delay due to normal system load■ Undetectable to user

• Rate limiting delay is on order of seconds• Timers do not fire early• Exact delays depend on heuristics

Page 87: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Coalescing and Rate Limiting

• Coalescing delay is on order of 100 ms■ About the same as delay due to normal system load■ Undetectable to user

• Rate limiting delay is on order of seconds• Timers do not fire early• Exact delays depend on heuristics• Configurable

Page 88: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Eyes demoThe Result

Page 89: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Eyes demo

0%

25%

50%

75%

100%

The ResultCP

U A

ctiv

ity

Page 90: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Eyes demo

0%

25%

50%

75%

100%

The Result

No App Nap

CPU

Act

ivity

Page 91: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Eyes demo

0%

25%

50%

75%

100%

The Result

With App Nap

No App Nap

CPU

Act

ivity

Page 92: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Eyes demo

0%

25%

50%

75%

100%

The Result

With App Nap

No App Nap

CPU

Act

ivity

Work Work Work Work

Page 93: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Eyes demo

0%

25%

50%

75%

100%

The Result

With App Nap

No App Nap

CPU

Act

ivity

Work Work Work Work

1 Hour

2012 15” MacBook Pro with Retina Display, 2.6 GHz Intel Core i7, OS X 10.9 Developer Preview

Page 94: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Switch from timer API to event APIImproving the Result

Page 95: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Switch from timer API to event APIImproving the Result

• Instead of polling key presses or mouse locations■ Use events

Page 96: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Switch from timer API to event APIImproving the Result

• Instead of polling key presses or mouse locations■ Use events

• Instead of repeatedly checking file content■ Use FSEvents, dispatch sources, or IPC

Page 97: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Switch from timer API to event APIImproving the Result

• Instead of polling key presses or mouse locations■ Use events

• Instead of repeatedly checking file content■ Use FSEvents, dispatch sources, or IPC

• Instead of timer-based synchronization■ Use semaphores or other locks

Page 98: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Switch from timer API to event APIImproving the Result

• Instead of polling key presses or mouse locations■ Use events

• Instead of repeatedly checking file content■ Use FSEvents, dispatch sources, or IPC

• Instead of timer-based synchronization■ Use semaphores or other locks

Energy Best Practices MarinaThursday 10:15AM

Page 99: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

DemoImproving the Eyes application

Page 100: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Responsiveness

• Important work should have higher priority

Page 101: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Responsiveness

• Important work should have higher priority•Apps in App Nap have lower priority

■ I/O■ CPU

Page 102: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Responsiveness

• Important work should have higher priority•Apps in App Nap have lower priority

■ I/O■ CPU

• To improve responsiveness, improve performance

Page 103: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Responsiveness

• Important work should have higher priority•Apps in App Nap have lower priority

■ I/O■ CPU

• To improve responsiveness, improve performance

Building Efficient OS X Apps Nob HillTuesday 4:30PM

Page 104: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

App Nap API

Page 105: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

App Nap API

• Find out when your app is visible•Add tolerance to timers• Tell system about user activities

Page 106: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Visibility

• Find out when a window or application is occluded■ On another space■ Another app is in front■ Screen saver is on

Page 107: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Visibility

• Find out when a window or application is occluded■ On another space■ Another app is in front■ Screen saver is on

•Halt expensive work when occluded

Page 108: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Visibility

• Find out when a window or application is occluded■ On another space■ Another app is in front■ Screen saver is on

•Halt expensive work when occluded• Refresh content when becoming visible

Page 109: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Window Occlusion

Visible

Page 110: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Window Occlusion

Visible

Page 111: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Window Occlusion

Visible

Page 112: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Window Occlusion

Visible

Page 113: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Window Occlusion

Occluded

Page 114: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Minimized Windows

Visible

Page 115: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Minimized Windows

Occluded

Page 116: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Application Occlusion

•Union of all application windows

Page 117: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Application Occlusion

•Union of all application windows•Menu bar does not count

■ Except for a status item

Page 118: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Application Occlusion

•Union of all application windows•Menu bar does not count

■ Except for a status item

Page 119: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Application Occlusion

•Union of all application windows•Menu bar does not count

■ Except for a status item

Page 120: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Application Occlusion

@protocol NSApplicationDelegate- (void)applicationDidChangeOcclusionState:(NSNotification *)notification;@end

@interface NSApplication- (NSApplicationOcclusionState)occlusionState;@end

typedef NS_OPTIONS(NSUInteger, NSApplicationOcclusionState) { NSApplicationOcclusionStateVisible = 1UL << 1,}

Page 121: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Window Occlusion

@protocol NSWindowDelegate- (void)windowDidChangeOcclusionState:(NSNotification *)notification;@end

@interface NSWindow- (NSWindowOcclusionState)occlusionState;@end

typedef NS_OPTIONS(NSUInteger, NSWindowOcclusionState) { NSWindowOcclusionStateVisible = 1UL << 1,}

Page 122: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Occlusion Example

@implementation EYEAppDelegate

- (void)applicationDidChangeOcclusionState:(NSNotification *)n{ if ([NSApp occlusionState] & NSApplicationOcclusionStateVisible) { // Visible } else { // Occluded }}

@end

Page 123: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Tolerance

•Most timers do not need to be hyper-accurate■ Default tolerance is applied to all timers

Page 124: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Tolerance

•Most timers do not need to be hyper-accurate■ Default tolerance is applied to all timers

•New API allows for increasing default tolerance

Page 125: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Tolerance

•Most timers do not need to be hyper-accurate■ Default tolerance is applied to all timers

•New API allows for increasing default tolerance• System fires timer at best time in tolerance window

Page 126: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Tolerance

Time 5 12 19 26

Page 127: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Tolerance

Time 5 12 19 26

Start

Page 128: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Tolerance

Time 5 12 19

7 7

26

7Interval

Start

Page 129: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Tolerance

Time 5 12 19

7 7

26

7Interval

3Tolerance 3 3

Start

Page 130: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

22

Timer Tolerance

Time 5 12 19

7 7

26

7Interval

3Tolerance 3 3

Start

8 15

Page 131: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

22

Timer Tolerance

Time 5 12 19

7 7

26

7Interval

3Tolerance 3 3

Start

8 15

Timer Timer Timer

Page 132: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

NSTimer Tolerance

@interface NSTimer- (void)setTolerance:(NSTimeInterval)tolerance;- (NSTimeInterval)tolerance;@end

Page 133: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

NSTimer Tolerance

// Create repeating timerNSTimer *timer = [NSTimer timerWithTimeInterval:7.0 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];

// Set fire date[timer setFireDate:[NSDate dateWithTimeIntervalSinceNow:5.0]];

// Set tolerance[timer setTolerance:3.0];

[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

Page 134: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Dispatch Timer Tolerance

dispatch_source_t timer;timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);

dispatch_source_set_event_handler(timer, ^{ /* Work goes here */ });

dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC), 7 * NSEC_PER_SEC, 3 * NSEC_PER_SEC);

dispatch_resume(timer);

Page 135: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Dispatch Strict Timers

dispatch_source_t timer;timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, DISPATCH_TIMER_STRICT, queue);

dispatch_source_set_event_handler(timer, ^{ /* Work goes here */ });

dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC), 7 * NSEC_PER_SEC, 700 * NSEC_PER_MSEC);

dispatch_resume(timer);

Page 136: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Tolerance

• Suggested tolerance is at least 10% of interval■ Exact value will be application specific

Page 137: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Tolerance

• Suggested tolerance is at least 10% of interval■ Exact value will be application specific

• Tolerance used regardless of App Nap

Page 138: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Tolerance

• Suggested tolerance is at least 10% of interval■ Exact value will be application specific

• Tolerance used regardless of App Nap• Strict timers are rare

■ Disables timer rate limiting■ You should still specify a tolerance

Page 139: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Timer Tolerance

• Suggested tolerance is at least 10% of interval■ Exact value will be application specific

• Tolerance used regardless of App Nap• Strict timers are rare

■ Disables timer rate limiting■ You should still specify a tolerance

• Critical mass effect

Page 140: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

User Activities

• Improves accuracy of App Nap heuristics

Page 141: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

User Activities

• Improves accuracy of App Nap heuristics•Use for long-running or asynchronous work

Page 142: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

User Activities

• Improves accuracy of App Nap heuristics•Use for long-running or asynchronous work• Cocoa API to prevent idle system sleep

Page 143: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

User Activities

• Improves accuracy of App Nap heuristics•Use for long-running or asynchronous work• Cocoa API to prevent idle system sleep• Includes automatic and sudden termination

Page 144: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

User Activities

@interface NSProcessInfo

@end

- (void)performActivityWithOptions:(NSActivityOptions)options reason:(NSString *)reason block:(void (^)())block;

Page 145: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

User Activities

@interface NSProcessInfo

@end

- (void)performActivityWithOptions:(NSActivityOptions)options reason:(NSString *)reason block:(void (^)())block;

- (id)beginActivityWithOptions:(NSActivityOptions)options reason:(NSString *)reason;

- (void)endActivity:(id)activity;

Page 146: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

NSActivityOptionsUser Activities

• Exporting, recording, processingNSActivityUserInitiatedNSActivityUserInitiatedAllowingIdleSystemSleep

Page 147: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

NSActivityOptionsUser Activities

• Exporting, recording, processingNSActivityUserInitiatedNSActivityUserInitiatedAllowingIdleSystemSleep

•MaintenanceNSActivityBackground

Page 148: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

NSActivityOptionsUser Activities

• Exporting, recording, processingNSActivityUserInitiatedNSActivityUserInitiatedAllowingIdleSystemSleep

•MaintenanceNSActivityBackground

• Latency sensitiveNSActivityUserInitiated | NSActivityLatencyCritical

Page 149: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

NSActivityOptionsUser Activities

• Idle system sleepNSActivityIdleDisplaySleepDisabledNSActivityIdleSystemSleepDisabled

Page 150: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

NSActivityOptionsUser Activities

• Idle system sleepNSActivityIdleDisplaySleepDisabledNSActivityIdleSystemSleepDisabled

• Sudden terminationNSActivitySuddenTerminationDisabled

Page 151: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

NSActivityOptionsUser Activities

• Idle system sleepNSActivityIdleDisplaySleepDisabledNSActivityIdleSystemSleepDisabled

• Sudden terminationNSActivitySuddenTerminationDisabled

•Automatic terminationNSActivityAutomaticTerminationDisabled

Page 152: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

User Activities

NSOperationQueue *queue = ...;

id token = [[NSProcessInfo processInfo] beginActivityWithOptions:NSActivityUserInitiated reason:@"Batch processing files"];

[queue addOperationWithBlock:^{ // Do work here

[[NSProcessInfo processInfo] endActivity:token];}];

Page 153: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Choosing the Right Activity

•Applications can have multiple concurrent activities■ NSActivityBackground for maintenance work■ NSActivityUserInitiated when user takes action

Page 154: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Choosing the Right Activity

•Applications can have multiple concurrent activities■ NSActivityBackground for maintenance work■ NSActivityUserInitiated when user takes action

•Avoid rapidly starting and ending activities

Page 155: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Choosing the Right Activity

•Applications can have multiple concurrent activities■ NSActivityBackground for maintenance work■ NSActivityUserInitiated when user takes action

•Avoid rapidly starting and ending activities• Idle system sleep assertions should be used with care

■ Don’t prevent idle sleep forever■ Verify power assertions are dropped

Page 156: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Verify power assertionsChoosing the Right Activity

Page 157: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Verify power assertionsChoosing the Right Activity

$ pmset -g assertions

Page 158: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Verify power assertionsChoosing the Right Activity

$ pmset -g assertionsAssertion status system-wide: BackgroundTask 0 PreventUserIdleDisplaySleep 0 PreventSystemSleep 0 PreventDiskIdle 0 PreventUserIdleSystemSleep 1 ExternalMedia 0 UserIsActive 0 ApplePushServiceTask 0Listed by owning process: pid 1963(Eyes): [0x0000000100000196] 00:03:36 PreventUserIdleSystemSleep named: "Keeping the computer awake"

Page 159: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

DemoAdopting App Nap API

Page 160: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Summary

Page 161: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Summary

• Software has a huge impact on energy efficiency

Page 162: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Summary

• Software has a huge impact on energy efficiency• To extend battery life

■ Stay idle as long as possible■ Avoid unnecessary work■ Race back to idle

Page 163: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Summary

• Software has a huge impact on energy efficiency• To extend battery life

■ Stay idle as long as possible■ Avoid unnecessary work■ Race back to idle

•Avoiding timers allows a longer idle time■ Instead, use event based API■ If you must use timers, add tolerance

Page 164: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Summary

• Software has a huge impact on energy efficiency• To extend battery life

■ Stay idle as long as possible■ Avoid unnecessary work■ Race back to idle

•Avoiding timers allows a longer idle time■ Instead, use event based API■ If you must use timers, add tolerance

•Use activity API to inform system of important user work

Page 165: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Energy Best Practices MarinaThursday 10:15AM

Building Efficient OS X Apps Nob HillTuesday 4:30PM

Related Sessions

Maximizing Battery Life on OS X MissionTuesday 11:30AM

Power and Performance: Optimizing Your Website for Great Battery Life and Responsive Scrolling

Russian HillWednesday 9:00AM

Page 166: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

Labs

Cocoa Lab Frameworks Lab AThursday 9:00AM

Cocoa Lab Frameworks Lab AWednesday 11:30AM

Cocoa Lab Frameworks Lab AFriday 9:00AM

Page 167: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result

More Information

Jake BehrensApp Frameworks [email protected]

Apple Developer Forumshttp://devforums.apple.com

Page 168: Improving Power Efficiency with App Nap · 2016-07-09 · •Mouse or keyboard input. When there is work to do Exiting Idle ... Switch from timer API to event API Improving the Result