Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from...
Transcript of Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from...
![Page 1: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/1.jpg)
These are confidential sessions—please refrain from streaming, blogging, or taking pictures
Session 712
Energy Best Practices
Matt JacobsonOS X Performance Mercenary
![Page 2: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/2.jpg)
![Page 3: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/3.jpg)
![Page 4: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/4.jpg)
![Page 5: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/5.jpg)
![Page 6: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/6.jpg)
![Page 7: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/7.jpg)
![Page 8: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/8.jpg)
![Page 9: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/9.jpg)
Topics
![Page 10: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/10.jpg)
• Recognizing energy issues
Topics
![Page 11: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/11.jpg)
• Recognizing energy issues•Diagnosing issues
Topics
![Page 12: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/12.jpg)
• Recognizing energy issues•Diagnosing issues•Avoiding common pitfalls
Topics
![Page 13: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/13.jpg)
• Recognizing energy issues•Diagnosing issues•Avoiding common pitfalls•Adopting best practices and new APIs
Topics
![Page 14: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/14.jpg)
What Uses Energy?
![Page 15: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/15.jpg)
What Uses Energy?
CPU
![Page 16: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/16.jpg)
What Uses Energy?
I/OCPU
![Page 17: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/17.jpg)
What Uses Energy?
I/OCPU Graphics
![Page 18: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/18.jpg)
What Uses Energy?
I/OCPU Graphics
![Page 19: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/19.jpg)
CPU Usage
![Page 20: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/20.jpg)
How to Use the CPU
![Page 21: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/21.jpg)
How to Use the CPU
•Modern CPUs have many cores, fast clocks, etc.
![Page 22: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/22.jpg)
How to Use the CPU
•Modern CPUs have many cores, fast clocks, etc.• Still limited by the size of the battery
![Page 23: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/23.jpg)
How to Use the CPU
•Modern CPUs have many cores, fast clocks, etc.• Still limited by the size of the battery• If you ask to run, you’ll run
![Page 24: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/24.jpg)
How to Use the CPU
•Modern CPUs have many cores, fast clocks, etc.• Still limited by the size of the battery• If you ask to run, you’ll run• Single app can impact battery life
![Page 25: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/25.jpg)
CPU Power DrawVs. idle
![Page 26: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/26.jpg)
CPU Power DrawVs. idle
1% CPU
10% CPU
100% CPU
10% higher power draw
2x power draw
10x power draw
![Page 27: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/27.jpg)
CPU Power DrawVs. idle
1% CPU
10% CPU
100% CPU
10% higher power draw
2x power draw
10x power draw
![Page 28: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/28.jpg)
CPU Power DrawVs. idle
1% CPU
10% CPU
100% CPU
10% higher power draw
2x power draw
10x power draw
![Page 29: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/29.jpg)
How Much Is Too Much?
• Be absolutely idle when app is not in use■ Eliminate nonuser-driven work■ Wait quietly for user input
![Page 30: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/30.jpg)
How Much Is Too Much?
• Be absolutely idle when app is not in use■ Eliminate nonuser-driven work■ Wait quietly for user input
• Be efficient when user requests action■ Performance = power■ Efficient, multithreaded algorithms win (use GCD)■ Then race back to idle
![Page 31: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/31.jpg)
Recognizing High CPU UsageActivity Monitor
![Page 32: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/32.jpg)
Recognizing High CPU UsageActivity Monitor
![Page 33: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/33.jpg)
![Page 34: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/34.jpg)
![Page 35: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/35.jpg)
![Page 36: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/36.jpg)
![Page 37: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/37.jpg)
![Page 38: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/38.jpg)
![Page 39: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/39.jpg)
top(1)Recognizing High CPU Usage
$ top -pid <pid>PID COMMAND %CPU TIME #TH #WQ #PORT #MREG MEM23106 StockWatcher 2.2 00:13.55 7/1 4/1 132 168 6340K
![Page 40: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/40.jpg)
top(1)Recognizing High CPU Usage
$ top -pid <pid>PID COMMAND %CPU TIME #TH #WQ #PORT #MREG MEM23106 StockWatcher 2.2 00:13.55 7/1 4/1 132 168 6340K
![Page 41: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/41.jpg)
top(1)Recognizing High CPU Usage
$ top -pid <pid> -aPID COMMAND %CPU TIME #TH #WQ #PORT #MREG MEM23106 StockWatcher 2.2 00:00.20 7/1 4/1 132 168 6340K
![Page 42: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/42.jpg)
top(1)Recognizing High CPU Usage
$ top -pid <pid> -aPID COMMAND %CPU TIME #TH #WQ #PORT #MREG MEM23106 StockWatcher 2.2 00:00.20 7/1 4/1 132 168 6340K
![Page 43: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/43.jpg)
![Page 44: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/44.jpg)
![Page 45: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/45.jpg)
![Page 46: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/46.jpg)
Diagnosing High CPU UsageResource exceptions
![Page 47: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/47.jpg)
Diagnosing High CPU UsageResource exceptions
kernel[0] <Debug>: process SomeApp[202] thread 1989 caught burning CPU! It used more than 50% CPU (Actual recent usage: 97%) over 180 seconds ...
![Page 48: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/48.jpg)
Diagnosing High CPU UsageResource exceptions
kernel[0] <Debug>: process SomeApp[202] thread 1989 caught burning CPU! It used more than 50% CPU (Actual recent usage: 97%) over 180 seconds ...
/Library/Logs/DiagnosticReports/SomeApp_2013-06-13.cpu_resource.spin
![Page 49: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/49.jpg)
Diagnosing High CPU UsageResource exceptions
kernel[0] <Debug>: process SomeApp[202] thread 1989 caught burning CPU! It used more than 50% CPU (Actual recent usage: 97%) over 180 seconds ...
/Library/Logs/DiagnosticReports/SomeApp_2013-06-13.cpu_resource.spinProcess: SomeApp [202]Architecture: x86_64Parent: launchd [137]
Powerstats for: SomeAppMicrostackshots: 64 samples 64 thread_start + 13 (libsystem_pthread.dylib) [0x7fff922b2fe9] 64 _pthread_start + 131 (libsystem_pthread.dylib) [0x7fff922ae7a0] 64 _pthread_body + 138 (libsystem_pthread.dylib) [0x7fff922ae90f] 64 run_thread + 17 (SomeApp) [0x10996bf11] 64 do_stuff + 9 (SomeApp) [0x10996bef9]
![Page 50: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/50.jpg)
Diagnosing High CPU UsageSecondary indicators
I/OCPU Graphics
![Page 51: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/51.jpg)
Diagnosing High CPU UsageSecondary indicators
I/OCPU Graphics
![Page 52: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/52.jpg)
fs_usageDiagnosing High CPU Usage
$ sudo fs_usage MyApp
![Page 53: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/53.jpg)
fs_usageDiagnosing High CPU Usage
$ sudo fs_usage MyApp20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:27 open ../Downloads.plist 0.000086 MyApp 20:29:27 write 0.000017 MyApp 20:29:27 close 0.000048 MyApp 20:29:27 stat64 MyIcon.png 0.000002 MyApp 20:29:27 stat64 MyIcon.png 0.000002 MyApp 20:29:27 stat64 MyIcon.png 0.000002 MyApp 20:29:27 stat64 MyIcon.png 0.000002 MyApp
![Page 54: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/54.jpg)
fs_usageDiagnosing High CPU Usage
$ sudo fs_usage MyApp20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:27 open ../Downloads.plist 0.000086 MyApp 20:29:27 write 0.000017 MyApp 20:29:27 close 0.000048 MyApp 20:29:27 stat64 MyIcon.png 0.000002 MyApp 20:29:27 stat64 MyIcon.png 0.000002 MyApp 20:29:27 stat64 MyIcon.png 0.000002 MyApp 20:29:27 stat64 MyIcon.png 0.000002 MyApp
![Page 55: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/55.jpg)
fs_usageDiagnosing High CPU Usage
$ sudo fs_usage MyApp20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:27 open ../Downloads.plist 0.000086 MyApp 20:29:27 write 0.000017 MyApp 20:29:27 close 0.000048 MyApp 20:29:27 stat64 MyIcon.png 0.000002 MyApp 20:29:27 stat64 MyIcon.png 0.000002 MyApp 20:29:27 stat64 MyIcon.png 0.000002 MyApp 20:29:27 stat64 MyIcon.png 0.000002 MyApp
![Page 56: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/56.jpg)
fs_usageDiagnosing High CPU Usage
$ sudo fs_usage MyApp20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:26 stat64 MyIcon.png 0.000002 MyApp 20:29:27 open ../Downloads.plist 0.000086 MyApp 20:29:27 write 0.000017 MyApp 20:29:27 close 0.000048 MyApp 20:29:27 stat64 MyIcon.png 0.000002 MyApp 20:29:27 stat64 MyIcon.png 0.000002 MyApp 20:29:27 stat64 MyIcon.png 0.000002 MyApp 20:29:27 stat64 MyIcon.png 0.000002 MyApp
Building Efficient OS X Apps Russian HillTuesday 2:00PM
![Page 57: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/57.jpg)
Diagnosing High CPU UsageSecondary indicators
I/OCPU Graphics
![Page 58: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/58.jpg)
Diagnosing High CPU UsageSecondary indicators
I/OCPU Graphics
![Page 59: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/59.jpg)
Diagnosing High CPU UsageQuartz Debug
![Page 60: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/60.jpg)
Diagnosing High CPU UsageQuartz Debug
![Page 61: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/61.jpg)
Diagnosing High CPU UsageQuartz Debug
![Page 62: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/62.jpg)
Diagnosing High CPU UsageQuartz Debug
![Page 63: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/63.jpg)
Diagnosing High CPU UsageQuartz Debug
Graphics Tools for Xcodehttp://developer.apple.com
![Page 64: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/64.jpg)
•A little is a lot• Ensure absolute idle•Watch with Activity Monitor
■ Especially when idle in the background
•Diagnose with Time Profiler
CPU Usage
![Page 65: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/65.jpg)
Timers
![Page 66: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/66.jpg)
Timers
![Page 67: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/67.jpg)
Timers
•Used to■ Schedule future/periodic events■ Drive animations
![Page 68: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/68.jpg)
Timers
•Used to■ Schedule future/periodic events■ Drive animations
• Keep apps out of idle
![Page 69: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/69.jpg)
Timers
•Used to■ Schedule future/periodic events■ Drive animations
• Keep apps out of idle• Can have outsize energy effect
![Page 70: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/70.jpg)
Timers
Power Consumption
Memory Controller/Caches
RAM, Buses, Clocks…
Baseline Idle Power
CPU PowerTime
![Page 71: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/71.jpg)
Timers
Power Consumption
Memory Controller/Caches
RAM, Buses, Clocks…
Timers Firing
Baseline Idle Power
CPU PowerTime
![Page 72: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/72.jpg)
Timers
Power Consumption
Memory Controller/Caches
RAM, Buses, Clocks…
Timers Firing
Baseline Idle Power
CPU Power
Useful work vastly outweighed bywake-up costs
Time
![Page 73: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/73.jpg)
Timers
Power Consumption
Memory Controller/Caches
RAM, Buses, Clocks…
Timers Firing
Baseline Idle Power
CPU Power
High frequencies inhibit platform idle
Useful work vastly outweighed bywake-up costs
Time
![Page 74: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/74.jpg)
What Is a Timer?
• Timer APIs■ Grand Central Dispatch timers■ CFRunLoopTimer■ NSTimer■ CFRunLoopRunInMode with timeout
![Page 75: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/75.jpg)
What Is a Timer?
• Low-level APIs■ sleep(), usleep(), nanosleep()
•APIs with timeouts■ pthread_cond_timedwait()■ dispatch_semaphore_wait()■ select(), poll(), kevent(), mach_msg()
![Page 76: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/76.jpg)
What Is a Timer?
•High-level APIs■ dispatch_after()■ -[NSObject performSelector:withObject:afterDelay:]■ NSProgressIndicator■ CVDisplayLink (OS X)/CADisplayLink (iOS)■ And more…
![Page 77: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/77.jpg)
Recognizing Timer IssuesActivity Monitor
![Page 78: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/78.jpg)
Recognizing Timer IssuesActivity Monitor
![Page 79: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/79.jpg)
Recognizing Timer IssuesActivity Monitor
![Page 80: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/80.jpg)
![Page 81: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/81.jpg)
![Page 82: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/82.jpg)
![Page 83: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/83.jpg)
![Page 84: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/84.jpg)
![Page 85: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/85.jpg)
![Page 86: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/86.jpg)
timerfiresDiagnosing Timer Issues
$ sudo timerfires -p <pid> -s
![Page 87: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/87.jpg)
timerfiresDiagnosing Timer Issues
$ sudo timerfires -p <pid> -sTIME(ms) PID PROCESS TYPE TIMER ROUTINE 435 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 933 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 1055 1603 MyApp dispatch MyApp`-[AppModel updateWidgets:] 1435 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 1935 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 2055 1603 MyApp dispatch MyApp`-[AppModel updateWidgets:] 2435 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 3004 1603 MyApp sleep libsystem_kernel.dylib`__semwait_signal+0xa libsystem_c.dylib`usleep+0x36 MyApp`-[AppModel pollForChange]+0x1a libdispatch.dylib`_dispatch_call_block_and_release+0xc
![Page 88: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/88.jpg)
timerfiresDiagnosing Timer Issues
$ sudo timerfires -p <pid> -sTIME(ms) PID PROCESS TYPE TIMER ROUTINE 435 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 933 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 1055 1603 MyApp dispatch MyApp`-[AppModel updateWidgets:] 1435 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 1935 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 2055 1603 MyApp dispatch MyApp`-[AppModel updateWidgets:] 2435 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 3004 1603 MyApp sleep libsystem_kernel.dylib`__semwait_signal+0xa libsystem_c.dylib`usleep+0x36 MyApp`-[AppModel pollForChange]+0x1a libdispatch.dylib`_dispatch_call_block_and_release+0xc
![Page 89: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/89.jpg)
timerfiresDiagnosing Timer Issues
$ sudo timerfires -p <pid> -sTIME(ms) PID PROCESS TYPE TIMER ROUTINE 435 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 933 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 1055 1603 MyApp dispatch MyApp`-[AppModel updateWidgets:] 1435 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 1935 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 2055 1603 MyApp dispatch MyApp`-[AppModel updateWidgets:] 2435 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 3004 1603 MyApp sleep libsystem_kernel.dylib`__semwait_signal+0xa libsystem_c.dylib`usleep+0x36 MyApp`-[AppModel pollForChange]+0x1a libdispatch.dylib`_dispatch_call_block_and_release+0xc
![Page 90: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/90.jpg)
timerfiresDiagnosing Timer Issues
$ sudo timerfires -p <pid> -sTIME(ms) PID PROCESS TYPE TIMER ROUTINE 435 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 933 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 1055 1603 MyApp dispatch MyApp`-[AppModel updateWidgets:] 1435 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 1935 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 2055 1603 MyApp dispatch MyApp`-[AppModel updateWidgets:] 2435 1603 MyApp CF MyApp`-[AppDelegate timerFired:] 3004 1603 MyApp sleep libsystem_kernel.dylib`__semwait_signal+0xa libsystem_c.dylib`usleep+0x36 MyApp`-[AppModel pollForChange]+0x1a libdispatch.dylib`_dispatch_call_block_and_release+0xc
![Page 91: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/91.jpg)
Don’t Use Timers for… Synchronization
![Page 92: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/92.jpg)
Don’t Use Timers for… Synchronization
BOOL workIsDone = NO;
/* thread one */void doWork(void) { /* wait for network ... */ workIsDone = YES;}
![Page 93: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/93.jpg)
Don’t Use Timers for… Synchronization
BOOL workIsDone = NO;
/* thread one */void doWork(void) { /* wait for network ... */ workIsDone = YES;}
/* thread two */void waitForWorkToFinish(void) { while (!workIsDone) { usleep(100000); /* 100 ms */ } [WorkController workDidFinish];}
![Page 94: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/94.jpg)
• Serial dispatch queues•Dispatch semaphores• Pthread condition variables
Use Built-in Synchronization Instead
![Page 95: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/95.jpg)
Use Built-in Synchronization Instead
BOOL workIsDone = NO;
/* thread one */void doWork(void) { /* wait for network ... */ workIsDone = YES;}
/* thread two */void waitForWorkToFinish(void) { while (!workIsDone) { usleep(100000); /* 100 ms */ } [WorkController workDidFinish];}
![Page 96: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/96.jpg)
Use Built-in Synchronization Instead
my_queue = dispatch_queue_create(“com.myapp.myq”, DISPATCH_QUEUE_SERIAL);
/* thread one */void doWork(void) { dispatch_sync(my_queue, ^{ /* wait for network ... */ });}
/* thread two */void waitForWorkToFinish(void) { dispatch_sync(my_queue, ^{ [WorkController workDidFinish]; });}
![Page 97: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/97.jpg)
Don’t Use Timers for… Polling
NSTimer *myTimer = [[NSTimer alloc] initWithFireDate:date interval:0.5 target:self selector:@selector(checkForFile:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:myTimer forMode:NSDefaultRunLoopMode];
![Page 98: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/98.jpg)
Use Event Streams Instead
• File system updates■ DISPATCH_SOURCE_TYPE_VNODE for small-scale updates■ FSEvents framework (OS X) for filesystem-wide updates
• Inter-process notifications■ XPC■ NSDistributedNotificationCenter■ notify(3)
![Page 99: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/99.jpg)
Use Event Streams Instead
•Disk Arbitration notifications• I/O Kit matching notifications•Network events
■ Apple Push Notification Service■ Bonjour■ Network reachability
![Page 100: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/100.jpg)
Use Event Streams Instead
NSTimer *myTimer = [[NSTimer alloc] initWithFireDate:date interval:0.5 target:self selector:@selector(checkForFile:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:myTimer forMode:NSDefaultRunLoopMode];
![Page 101: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/101.jpg)
Use Event Streams Instead
const uint64_t flags = DISPATCH_VNODE_DELETE | DISPATCH_VNODE_WRITE;dispatch_source_t my_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, fd, flags, queue);
dispatch_source_set_event_handler(my_source, ^{ [self checkForFile];});
dispatch_resume(my_source);
![Page 102: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/102.jpg)
Specify Suitable Timeouts
![Page 103: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/103.jpg)
Specify Suitable Timeouts
for (;;) { long rv; dispatch_time_t timeout = dispatch_time(DISPATCH_TIME_NOW, 500 * NSEC_PER_MSEC);
rv = dispatch_semaphore_wait(my_sema, timeout); if (havePendingWork) { [self doPendingWork]; }}
![Page 104: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/104.jpg)
Specify Suitable Timeouts
for (;;) { long rv; dispatch_time_t timeout = DISPATCH_TIME_FOREVER;
rv = dispatch_semaphore_wait(my_sema, timeout); if (havePendingWork) { [self doPendingWork]; }}
![Page 105: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/105.jpg)
Manage Repeating Timers
NSTimer *myTimer = [[NSTimer alloc] initWithFireDate:date interval:1.0 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];
/* ... */
/* myTimer not invalidated! */
![Page 106: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/106.jpg)
Manage Repeating Timers
NSTimer *myTimer = [[NSTimer alloc] initWithFireDate:date interval:1.0 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];
/* ... */
[myTimer invalidate];
![Page 107: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/107.jpg)
Specify Timer Tolerance
•Hint to the system of timer flexibility•Allows system to batch work
![Page 108: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/108.jpg)
Specify Timer Tolerance
• For dispatch timers
dispatch_source_t my_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);dispatch_source_set_timer(my_timer, DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC, NSEC_PER_SEC / 10);
dispatch_source_set_event_handler(my_timer, ^{ [self timerFired];});dispatch_resume(my_timer);
![Page 109: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/109.jpg)
Specify Timer Tolerance
• For CFRunLoopTimers
CFRunLoopTimerRef myTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, fireDate, 1.0, 0, 0, &timerFired, NULL);CFRunLoopTimerSetTolerance(myTimer, 0.1);
CFRunLoopAddTimer(CFRunLoopGetCurrent(), myTimer, kCFRunLoopDefaultMode);
![Page 110: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/110.jpg)
Specify Timer Tolerance
• For NSTimers
NSTimer *myTimer = [[NSTimer alloc] initWithFireDate:date interval:1.0 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];[myTimer setTolerance:0.1];
[[NSRunLoop currentRunLoop] addTimer:myTimer forMode:NSDefaultRunLoopMode];
![Page 111: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/111.jpg)
DemoPutting it all together
![Page 112: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/112.jpg)
• Be mindful of wakeup overhead•Monitor for wakeups in Activity Monitor•Debug with timerfires• Specify timer tolerance
Responsible Timer Use
![Page 113: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/113.jpg)
Smart Background Work
![Page 114: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/114.jpg)
Smart Background Work
• Be idle when you can, eliminating…■ extraneous CPU usage■ unnecessary timers
• Be smart when you can’t
![Page 115: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/115.jpg)
Periodic Animations
• Stop driving UI the user isn’t watching•Apple apps work like this
■ Photo Booth■ FaceTime■ App Store
![Page 116: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/116.jpg)
Frontmost App Notification
•App became frontmost/non-frontmost■ Implement -applicationDidResignActive: and -applicationDidBecomeActive: in your app delegate
■ Or checkif ([NSApp isActive]) ...
![Page 117: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/117.jpg)
![Page 118: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/118.jpg)
![Page 119: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/119.jpg)
Occlusion Notifications
![Page 120: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/120.jpg)
Occlusion Notifications
•App occluded■ Implement -applicationDidChangeOcclusionState: in your app delegate■ Or check
if ([NSApp occlusionState] & NSApplicationOcclusionStateVisible) ...
![Page 121: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/121.jpg)
Occlusion Notifications
•App occluded■ Implement -applicationDidChangeOcclusionState: in your app delegate■ Or check
if ([NSApp occlusionState] & NSApplicationOcclusionStateVisible) ...
•Window occluded■ Implement -windowDidChangeOcclusionState: in your window delegate■ Or check
if ([window occlusionState] & NSWindowOcclusionStateVisible) ...
![Page 122: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/122.jpg)
Occlusion Notifications
•App occluded■ Implement -applicationDidChangeOcclusionState: in your app delegate■ Or check
if ([NSApp occlusionState] & NSApplicationOcclusionStateVisible) ...
•Window occluded■ Implement -windowDidChangeOcclusionState: in your window delegate■ Or check
if ([window occlusionState] & NSWindowOcclusionStateVisible) ...
Improving Power Efficiency with App Nap Pacific HeightsWednesday 10:15AM
![Page 123: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/123.jpg)
Batching Periodic Work
•Group maintenance operations together•Do them later with user-requested activity• Replaces timer-driven “cleanup” or “timeout” work
■ Causes wakeups■ Hurts your race to idle
![Page 124: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/124.jpg)
Batching Periodic Work
- (void)cacheImage:(NSImage *)anImage { /* ... */
[self performSelector:@selector(removeImageIfStale:) withObject:anImage afterDelay:5.0];}
- (void)removeImageIfStale:(NSImage *)anImage { if ([self imageIsStale:anImage]) [self removeImage:anImage]; else [self performSelector:@selector(removeImageIfStale:) withObject:anImage afterDelay:5.0];}
![Page 125: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/125.jpg)
Batching Periodic Work
- (void)cacheImage:(NSImage *)anImage { /* ... */
[imageArray addObject:anImage];}
- (void)handleUserEvent { dispatch_async(..., ^{ for (NSImage *image in imageArray) if ([self imageIsStale:anImage]) [self removeImage:anImage]; });
/* ... */}
![Page 126: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/126.jpg)
Centralized Task Scheduling
• Periodic work that can wait for wall power■ Clean-up work■ Syncing■ Indexing■ Downloading new content
•New XPC API
![Page 127: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/127.jpg)
Centralized Task Scheduling
xpc_object_t criteria = xpc_dictionary_create(NULL, NULL, 0);xpc_dictionary_set_bool(criteria, XPC_ACTIVITY_REPEATING, FALSE);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_DELAY, 3600);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_GRACE_PERIOD, 6 * 3600);xpc_dictionary_set_string(criteria, XPC_ACTIVITY_PRIORITY, XPC_ACTIVITY_PRIORITY_MAINTENANCE);
xpc_activity_register("com.myapp.MySimpleActivity", criteria, ^(xpc_activity_t activity) { /* do background work here */ });
![Page 128: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/128.jpg)
Centralized Task Scheduling
xpc_object_t criteria = xpc_dictionary_create(NULL, NULL, 0);xpc_dictionary_set_bool(criteria, XPC_ACTIVITY_REPEATING, FALSE);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_DELAY, 3600);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_GRACE_PERIOD, 6 * 3600);xpc_dictionary_set_string(criteria, XPC_ACTIVITY_PRIORITY, XPC_ACTIVITY_PRIORITY_MAINTENANCE);
xpc_activity_register("com.myapp.MySimpleActivity", criteria, ^(xpc_activity_t activity) { /* do background work here */ });
![Page 129: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/129.jpg)
Centralized Task Scheduling
xpc_object_t criteria = xpc_dictionary_create(NULL, NULL, 0);xpc_dictionary_set_bool(criteria, XPC_ACTIVITY_REPEATING, FALSE);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_DELAY, 3600);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_GRACE_PERIOD, 6 * 3600);xpc_dictionary_set_string(criteria, XPC_ACTIVITY_PRIORITY, XPC_ACTIVITY_PRIORITY_MAINTENANCE);
xpc_activity_register("com.myapp.MySimpleActivity", criteria, ^(xpc_activity_t activity) { /* do background work here */ });
![Page 130: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/130.jpg)
Centralized Task Scheduling
xpc_object_t criteria = xpc_dictionary_create(NULL, NULL, 0);xpc_dictionary_set_bool(criteria, XPC_ACTIVITY_REPEATING, FALSE);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_DELAY, 3600);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_GRACE_PERIOD, 6 * 3600);xpc_dictionary_set_string(criteria, XPC_ACTIVITY_PRIORITY, XPC_ACTIVITY_PRIORITY_MAINTENANCE);
xpc_activity_register("com.myapp.MySimpleActivity", criteria, ^(xpc_activity_t activity) { /* do background work here */ });
![Page 131: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/131.jpg)
Centralized Task Scheduling
xpc_object_t criteria = xpc_dictionary_create(NULL, NULL, 0);xpc_dictionary_set_bool(criteria, XPC_ACTIVITY_REPEATING, FALSE);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_DELAY, 3600);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_GRACE_PERIOD, 6 * 3600);xpc_dictionary_set_string(criteria, XPC_ACTIVITY_PRIORITY, XPC_ACTIVITY_PRIORITY_MAINTENANCE);
xpc_activity_register("com.myapp.MySimpleActivity", criteria, ^(xpc_activity_t activity) { /* do background work here */ });
![Page 132: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/132.jpg)
Centralized Task Scheduling
xpc_object_t criteria = xpc_dictionary_create(NULL, NULL, 0);xpc_dictionary_set_bool(criteria, XPC_ACTIVITY_REPEATING, FALSE);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_DELAY, 3600);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_GRACE_PERIOD, 6 * 3600);xpc_dictionary_set_string(criteria, XPC_ACTIVITY_PRIORITY, XPC_ACTIVITY_PRIORITY_MAINTENANCE);
xpc_activity_register("com.myapp.MySimpleActivity", criteria, ^(xpc_activity_t activity) { /* do background work here */ });
![Page 133: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/133.jpg)
Centralized Task Scheduling
xpc_object_t criteria = xpc_dictionary_create(NULL, NULL, 0);xpc_dictionary_set_bool(criteria, XPC_ACTIVITY_REPEATING, FALSE);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_DELAY, 3600);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_GRACE_PERIOD, 6 * 3600);xpc_dictionary_set_string(criteria, XPC_ACTIVITY_PRIORITY, XPC_ACTIVITY_PRIORITY_MAINTENANCE);
xpc_activity_register("com.myapp.MySimpleActivity", criteria, ^(xpc_activity_t activity) { /* do background work here */ });
![Page 134: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/134.jpg)
Centralized Task Scheduling
xpc_object_t criteria = xpc_dictionary_create(NULL, NULL, 0);xpc_dictionary_set_bool(criteria, XPC_ACTIVITY_REPEATING, FALSE);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_DELAY, 3600);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_GRACE_PERIOD, 6 * 3600);xpc_dictionary_set_string(criteria, XPC_ACTIVITY_PRIORITY, XPC_ACTIVITY_PRIORITY_MAINTENANCE);
xpc_activity_register("com.myapp.MySimpleActivity", criteria, ^(xpc_activity_t activity) { /* do background work here */ });
![Page 135: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/135.jpg)
Centralized Task Scheduling
Efficient Design with XPC Russian HillTuesday 2:00PM
xpc_object_t criteria = xpc_dictionary_create(NULL, NULL, 0);xpc_dictionary_set_bool(criteria, XPC_ACTIVITY_REPEATING, FALSE);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_DELAY, 3600);xpc_dictionary_set_int64(criteria, XPC_ACTIVITY_GRACE_PERIOD, 6 * 3600);xpc_dictionary_set_string(criteria, XPC_ACTIVITY_PRIORITY, XPC_ACTIVITY_PRIORITY_MAINTENANCE);
xpc_activity_register("com.myapp.MySimpleActivity", criteria, ^(xpc_activity_t activity) { /* do background work here */ });
![Page 136: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/136.jpg)
Summary
![Page 137: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/137.jpg)
Summary
•A little CPU costs a lot
![Page 138: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/138.jpg)
Summary
•A little CPU costs a lot• So achieve absolute idle
![Page 139: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/139.jpg)
Summary
•A little CPU costs a lot• So achieve absolute idle• Test early, test often
![Page 140: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/140.jpg)
More Information
Paul DanboldCore OS Technologies [email protected]
Dave DeLongApp Frameworks [email protected]
DocumentationInstruments User Guidehttp://developer.apple.com
Apple Developer Forumshttp://devforums.apple.com
![Page 141: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/141.jpg)
Related Sessions
Improving Power Efficiency with App Nap Pacific HeightsWednesday 10:15AM
Maximizing Battery Life on OS X MissionTuesday 11:30AM
Efficient Design with XPC Russian HillTuesday 2:00PM
Building Efficient OS X Apps Nob HillTuesday 4:30PM
Power and Performance: Optimizing Your Website for Great Battery Life and Responsive Scrolling
Russian HillWednesday 9:00AM
![Page 142: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/142.jpg)
Labs
Power and Performance for OS X Apps Core OS Lab AWednesday 10:15AM
![Page 143: Energy Best Practices - Apple Inc.€¦ · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 712 Energy Best Practices Matt Jacobson](https://reader034.fdocuments.in/reader034/viewer/2022051410/602e7948f5d49a5b8150afdb/html5/thumbnails/143.jpg)