-
Notifications
You must be signed in to change notification settings - Fork 48
/
209.srt
4204 lines (3080 loc) · 91.9 KB
/
209.srt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:00:00.506 --> 00:00:09.516 A:middle
[ Silence ]
00:00:10.016 --> 00:00:12.000 A:middle
[ Music ]
00:00:12.756 --> 00:00:13.396 A:middle
>> Good morning.
00:00:15.386 --> 00:00:17.946 A:middle
Welcome to "Improving Power
Efficiency with AppNap."
00:00:18.346 --> 00:00:20.366 A:middle
My name is Tony Parker and
I'm a software engineer
00:00:20.366 --> 00:00:21.866 A:middle
on the Cocoa Frameworks
Team at Apple.
00:00:22.036 --> 00:00:25.906 A:middle
So today we're going to
go over three topics.
00:00:26.196 --> 00:00:27.606 A:middle
First, what is AppNap?
00:00:28.296 --> 00:00:29.106 A:middle
Then we're going
to go into a lot
00:00:29.106 --> 00:00:31.036 A:middle
of detail on how AppNap works.
00:00:31.686 --> 00:00:33.896 A:middle
And finally we're going to
cover AppNap and other power
00:00:33.896 --> 00:00:35.996 A:middle
and energy related API.
00:00:36.516 --> 00:00:38.686 A:middle
So first let's talk
about what AppNap is.
00:00:39.386 --> 00:00:42.656 A:middle
So we live in a world
today on OS X
00:00:43.016 --> 00:00:45.266 A:middle
where users expect
both long battery life
00:00:45.266 --> 00:00:47.886 A:middle
and at the same time
high performance
00:00:47.886 --> 00:00:49.286 A:middle
responsive applications.
00:00:49.906 --> 00:00:51.606 A:middle
However, because
it's a multitasking,
00:00:51.606 --> 00:00:54.486 A:middle
multi user operating system,
all apps actually have
00:00:54.556 --> 00:00:59.466 A:middle
about equal access to limited
resources like CPU time, disk IO
00:00:59.466 --> 00:01:01.666 A:middle
and most importantly
for this talk, energy.
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:00:59.466 --> 00:01:01.666 A:middle
and most importantly
for this talk, energy.
00:01:02.246 --> 00:01:06.656 A:middle
So in designing this feature, we
wanted to focus system resources
00:01:06.656 --> 00:01:08.716 A:middle
on the most important user work.
00:01:09.406 --> 00:01:12.026 A:middle
And the benefit of that is going
to be increased battery life
00:01:12.366 --> 00:01:14.116 A:middle
and improved responsiveness.
00:01:14.646 --> 00:01:18.536 A:middle
Now the tricky part of
course is deciding what
00:01:18.536 --> 00:01:22.026 A:middle
that important work is and we do
that with a set of heuristics.
00:01:22.476 --> 00:01:24.756 A:middle
So for example, we look at
whether an application is
00:01:24.756 --> 00:01:26.306 A:middle
in the foreground
- typically the one
00:01:26.306 --> 00:01:28.216 A:middle
with the menu bar -
or the background.
00:01:28.956 --> 00:01:31.066 A:middle
Typically a foreground
application is doing more
00:01:31.066 --> 00:01:32.096 A:middle
important user work.
00:01:32.096 --> 00:01:36.406 A:middle
We also look at the
application type.
00:01:36.776 --> 00:01:38.496 A:middle
So a system daemon
00:01:38.496 --> 00:01:41.156 A:middle
or a background agent is
typically doing less important
00:01:41.156 --> 00:01:43.686 A:middle
work than an application that
the user can actually sort
00:01:43.686 --> 00:01:45.916 A:middle
of see and interact with
on the doc for example.
00:01:46.436 --> 00:01:50.516 A:middle
We can also take into
account the visibility
00:01:50.676 --> 00:01:52.956 A:middle
of your application's
windows on screen.
00:01:53.296 --> 00:01:55.966 A:middle
So an application that has a
window that's completely hidden
00:01:55.966 --> 00:02:00.316 A:middle
by other windows or on another
space that's been moved away is
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:01:55.966 --> 00:02:00.316 A:middle
by other windows or on another
space that's been moved away is
00:02:00.316 --> 00:02:02.196 A:middle
typically doing less
important work to the user
00:02:02.196 --> 00:02:05.506 A:middle
than the ones it can see
right in front of them.
00:02:05.606 --> 00:02:07.356 A:middle
And also we look at
drawing activity.
00:02:07.446 --> 00:02:09.096 A:middle
So an application
that can update it --
00:02:09.096 --> 00:02:11.376 A:middle
it's updating itself and
displaying new content
00:02:11.376 --> 00:02:12.886 A:middle
to the user, that
might be something
00:02:12.886 --> 00:02:14.886 A:middle
that the user is looking
at and actively watching.
00:02:15.116 --> 00:02:17.546 A:middle
And that would indicate
more important work.
00:02:18.936 --> 00:02:20.796 A:middle
Now even if an application
is completely hidden,
00:02:20.796 --> 00:02:23.896 A:middle
if it's playing audio, that's
obviously also perceptible
00:02:23.896 --> 00:02:25.706 A:middle
to the user so we
count that as well.
00:02:25.706 --> 00:02:28.496 A:middle
And of course, event processing.
00:02:28.496 --> 00:02:31.686 A:middle
User events and events like
hot keys are also considered.
00:02:32.296 --> 00:02:36.406 A:middle
We can also use the existing
I/O Kit Power Searching API.
00:02:36.926 --> 00:02:37.876 A:middle
You might be familiar with this.
00:02:37.876 --> 00:02:39.206 A:middle
It's been on OS X for a while
00:02:39.376 --> 00:02:41.146 A:middle
and it lets you tell
the system you know,
00:02:41.146 --> 00:02:43.426 A:middle
"Don't put the system -- don't
allow the system to idle sleep
00:02:43.586 --> 00:02:45.376 A:middle
because I'm doing something
that I need to finish."
00:02:46.396 --> 00:02:49.066 A:middle
And finally we have a
new set of AppNap APIs
00:02:49.856 --> 00:02:52.726 A:middle
which let you help improve these
heuristics by telling the system
00:02:52.726 --> 00:02:54.386 A:middle
about the kinds of
activities you're doing.
00:02:54.386 --> 00:02:58.396 A:middle
So I want to show you a quick
demo of AppNap in action.
00:02:59.446 --> 00:03:01.276 A:middle
Okay, so here we go.
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:02:59.446 --> 00:03:01.276 A:middle
Okay, so here we go.
00:03:01.276 --> 00:03:03.476 A:middle
If you've ever been to a
presentation like this one
00:03:03.816 --> 00:03:06.196 A:middle
and had trouble following what
a presenter like me is doing,
00:03:06.536 --> 00:03:07.946 A:middle
I've got the App here for you.
00:03:08.076 --> 00:03:10.276 A:middle
And it may also be familiar
to some of you old timers.
00:03:10.906 --> 00:03:12.716 A:middle
As you can see, these apps --
00:03:12.716 --> 00:03:14.196 A:middle
they're 2 copies
of the same app.
00:03:14.516 --> 00:03:16.626 A:middle
It's following my mouse as I
move it around the screen here.
00:03:17.176 --> 00:03:21.226 A:middle
And I also have Activity
Monitor open.
00:03:21.286 --> 00:03:22.896 A:middle
And I want to show you a
couple new things we've added
00:03:22.896 --> 00:03:26.086 A:middle
to Activity Monitor that can
really help users understand
00:03:26.236 --> 00:03:27.566 A:middle
where their energy is going.
00:03:27.566 --> 00:03:28.626 A:middle
So there are 2 columns
00:03:28.626 --> 00:03:30.096 A:middle
in particular I want
to focus on here.
00:03:30.446 --> 00:03:31.736 A:middle
First, the AppNap column.
00:03:32.026 --> 00:03:32.756 A:middle
Now you can see that both
00:03:32.756 --> 00:03:35.786 A:middle
of these applications are
-- say "No" right now.
00:03:36.236 --> 00:03:37.996 A:middle
In fact, one of these
applications is completely
00:03:37.996 --> 00:03:40.466 A:middle
unmodified and the other
one I've explicitly modified
00:03:40.466 --> 00:03:41.566 A:middle
to prevent AppNap.
00:03:42.166 --> 00:03:44.536 A:middle
The other column is
the energy impact.
00:03:44.896 --> 00:03:47.176 A:middle
Now you notice that this
column is unitless and that's
00:03:47.176 --> 00:03:50.086 A:middle
because it's really sort of an
aggregate score of the kinds
00:03:50.086 --> 00:03:53.286 A:middle
of things an application can do
that can cause battery drain.
00:03:53.886 --> 00:03:56.866 A:middle
So I mentioned that visibility
is one of the heuristics
00:03:56.866 --> 00:03:59.366 A:middle
that we use for determining
eligibility for AppNap.
00:03:59.696 --> 00:04:02.096 A:middle
So what I'm going to do is
move my Activity Monitor window
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:03:59.696 --> 00:04:02.096 A:middle
So what I'm going to do is
move my Activity Monitor window
00:04:02.096 --> 00:04:06.136 A:middle
in front of these other
two windows and we'll see
00:04:06.136 --> 00:04:09.306 A:middle
after a few seconds the
system will decide that one
00:04:09.306 --> 00:04:11.436 A:middle
of these apps - the one
that was unmodified -
00:04:11.856 --> 00:04:13.996 A:middle
can go into that AppNap state.
00:04:13.996 --> 00:04:16.146 A:middle
And that's going to
reduce its energy impact
00:04:16.716 --> 00:04:18.685 A:middle
to a much lower level.
00:04:18.685 --> 00:04:20.616 A:middle
In fact here you
see it's at zero.
00:04:21.546 --> 00:04:23.356 A:middle
However, if I just - you
know - move my window
00:04:23.356 --> 00:04:25.676 A:middle
out of the way a little
bit, you see both windows --
00:04:25.676 --> 00:04:28.226 A:middle
or both applications still
appear responsive to the user.
00:04:29.036 --> 00:04:32.146 A:middle
And so the idea here is to
not interrupt user's work
00:04:32.186 --> 00:04:34.926 A:middle
but instead focus in this
case the battery life
00:04:34.926 --> 00:04:37.406 A:middle
on the applications that
are doing important work.
00:04:37.786 --> 00:04:39.716 A:middle
And we'll see what a difference
this makes in a little bit.
00:04:39.716 --> 00:04:42.676 A:middle
Now let's go back to our slides.
00:04:42.676 --> 00:04:45.256 A:middle
So let's go into some
detail on how all
00:04:45.256 --> 00:04:46.686 A:middle
of this AppNap is working.
00:04:47.266 --> 00:04:50.326 A:middle
So first I want to define
a couple terms that we sort
00:04:50.626 --> 00:04:52.176 A:middle
of tend to throw around
a little bit loosely.
00:04:52.536 --> 00:04:56.116 A:middle
Power: so power is actually
a rate and it's the rate
00:04:56.116 --> 00:04:57.356 A:middle
at which energy is consumed.
00:04:57.616 --> 00:04:59.526 A:middle
One way to measure
that would be in watts.
00:04:59.526 --> 00:05:03.836 A:middle
Energy on the other hand is the
stored potential to do work.
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:04:59.526 --> 00:05:03.836 A:middle
Energy on the other hand is the
stored potential to do work.
00:05:04.096 --> 00:05:06.576 A:middle
And one way to measure that
might be in watt hours.
00:05:06.946 --> 00:05:09.706 A:middle
So for example let's say I
have a 50 watt hour battery
00:05:10.026 --> 00:05:12.706 A:middle
and I want a 7 hour battery
life from that battery.
00:05:13.056 --> 00:05:16.466 A:middle
Well I can do some simple
division: 50 watt hours divided
00:05:16.466 --> 00:05:20.336 A:middle
by 7 hours and that gives me
a rate of about 7.1 watts.
00:05:20.796 --> 00:05:24.226 A:middle
So what that means is that if
I'm using more than 7.1 watts,
00:05:24.516 --> 00:05:26.746 A:middle
my battery life will
be less than 7 hours.
00:05:27.026 --> 00:05:29.526 A:middle
And if I use less
than 7.1 watts,
00:05:29.736 --> 00:05:32.366 A:middle
I will get a longer battery
life of above 7 hours.
00:05:33.266 --> 00:05:36.706 A:middle
Now this 7.1 watts has to power
the entire system on a laptop.
00:05:36.936 --> 00:05:40.386 A:middle
That includes the screen and
the backlight, the GPU, network,
00:05:40.386 --> 00:05:42.906 A:middle
storage, memory and finally CPU.
00:05:43.786 --> 00:05:45.236 A:middle
Now you may look at
this list and think,
00:05:45.236 --> 00:05:46.796 A:middle
"There's some big
ticket items on there
00:05:47.086 --> 00:05:48.746 A:middle
like the screen and the GPU."
00:05:49.056 --> 00:05:49.906 A:middle
And you'd be right.
00:05:50.056 --> 00:05:51.926 A:middle
Those do use a significant
amount of power.
00:05:52.276 --> 00:05:54.956 A:middle
However today we're going
to focus instead on the CPU.
00:05:55.246 --> 00:05:56.176 A:middle
And that's for two reasons.
00:05:56.526 --> 00:05:59.026 A:middle
First, as software engineers,
this is the thing we're going
00:05:59.026 --> 00:06:00.356 A:middle
to have the most impact on.
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:05:59.026 --> 00:06:00.356 A:middle
to have the most impact on.
00:06:00.776 --> 00:06:02.146 A:middle
But second and most importantly,
00:06:02.146 --> 00:06:04.926 A:middle
the CPU actually has the
highest dynamic range
00:06:05.036 --> 00:06:06.316 A:middle
out of all of these components.
00:06:06.786 --> 00:06:08.726 A:middle
So let me show you
what I mean by that.
00:06:09.736 --> 00:06:12.736 A:middle
If we look at the power
usage of a modern Intel chip,
00:06:13.336 --> 00:06:15.536 A:middle
you can see at its most
idle state we can use
00:06:15.536 --> 00:06:17.296 A:middle
as little as 0.4 watts.
00:06:18.316 --> 00:06:20.286 A:middle
However, if we're
executing any code at all
00:06:20.286 --> 00:06:21.756 A:middle
at the nominal frequency
of the chip,
00:06:22.256 --> 00:06:24.476 A:middle
we're going to go all
the way up to 15 watts.
00:06:24.936 --> 00:06:26.686 A:middle
Now this is just for the CPU.
00:06:27.066 --> 00:06:29.946 A:middle
So here you can see, if
we had a budget of 7 watts
00:06:30.076 --> 00:06:32.776 A:middle
and we're running a 15
watt CPU, we're not going
00:06:32.776 --> 00:06:34.836 A:middle
to get the battery life
of 7 hours that we wanted.
00:06:35.336 --> 00:06:37.556 A:middle
And furthermore, if we're
running at turbo frequencies,
00:06:37.836 --> 00:06:40.046 A:middle
then it goes all the
way up to 25 watts.
00:06:40.916 --> 00:06:44.386 A:middle
So there's a gigantic difference
between the low power idle state
00:06:44.656 --> 00:06:47.416 A:middle
and the high power executing
code or turbo states.
00:06:47.896 --> 00:06:49.666 A:middle
And so that leads us
into the three key rules
00:06:49.666 --> 00:06:50.836 A:middle
of extending battery life.
00:06:51.276 --> 00:06:52.606 A:middle
The first is that
we need to stay
00:06:52.606 --> 00:06:56.276 A:middle
at that low power 0.4 watt
idle state as long as possible.
00:06:56.916 --> 00:07:00.366 A:middle
And to do that - Number 2 - we
need to avoid unnecessary work
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:06:56.916 --> 00:07:00.366 A:middle
And to do that - Number 2 - we
need to avoid unnecessary work
00:07:00.726 --> 00:07:02.546 A:middle
like drawing a pair of
eyes in the background
00:07:02.546 --> 00:07:03.506 A:middle
when you can't even see them.
00:07:04.066 --> 00:07:07.436 A:middle
And third, when we do work
which is okay from time to time
00:07:07.436 --> 00:07:09.986 A:middle
if the user's asked us to
do it, we need to return
00:07:09.986 --> 00:07:12.996 A:middle
to that idle state as quickly as
possible so that we can remain
00:07:12.996 --> 00:07:14.606 A:middle
in that 0.4 watt idle state.
00:07:15.146 --> 00:07:18.206 A:middle
Now you might be surprised
00:07:18.206 --> 00:07:20.536 A:middle
at how quickly we can actually
switch between these states.
00:07:20.766 --> 00:07:21.906 A:middle
So here I've got a use case
00:07:21.906 --> 00:07:25.936 A:middle
of visiting the www.Apple.com
website in Safari on Wi-Fi
00:07:25.936 --> 00:07:28.036 A:middle
on my demo machine, and
what I've graphed here
00:07:28.036 --> 00:07:30.666 A:middle
on the vertical axis
is CPU activity.
00:07:30.906 --> 00:07:32.486 A:middle
This is not the same
as CPU time.
00:07:32.716 --> 00:07:36.236 A:middle
For one thing, it's the whole
CPU: not just one process.
00:07:36.236 --> 00:07:38.116 A:middle
And also, it's more
a measurement
00:07:38.116 --> 00:07:40.576 A:middle
of how long we could stay
in that idle state instead
00:07:40.576 --> 00:07:42.436 A:middle
of how much time
we were executing.
00:07:42.876 --> 00:07:44.456 A:middle
So at the bottom
at zero percent,
00:07:44.726 --> 00:07:47.066 A:middle
that's our most idle state
for the entire sample period:
00:07:47.066 --> 00:07:48.116 A:middle
that's the lowest power.
00:07:48.466 --> 00:07:51.346 A:middle
And at the top, 100 percent
would be the least idle,
00:07:51.446 --> 00:07:53.626 A:middle
executing all the time
during the sample interval.
00:07:54.206 --> 00:07:58.216 A:middle
So here's what it looked like.
00:07:59.016 --> 00:08:02.236 A:middle
At the beginning, I was typing
Apple.com into the address bar
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:07:59.016 --> 00:08:02.236 A:middle
At the beginning, I was typing
Apple.com into the address bar
00:08:02.336 --> 00:08:04.596 A:middle
and so that's not just the key
presses that we need to handle:
00:08:04.596 --> 00:08:07.736 A:middle
that also includes Auto Complete
or looking up bookmarks,
00:08:08.036 --> 00:08:10.656 A:middle
drawing the actual menu
on screen and so forth.
00:08:11.606 --> 00:08:13.866 A:middle
This vertical spike here
is where I've hit Enter
00:08:13.866 --> 00:08:15.636 A:middle
and we began downloading
the webpage
00:08:15.736 --> 00:08:16.896 A:middle
and rendering the content.
00:08:17.366 --> 00:08:19.036 A:middle
Now what's interesting
about this, is if you look
00:08:19.036 --> 00:08:21.706 A:middle
at the number there, we're
still at this time at the peak
00:08:21.706 --> 00:08:23.296 A:middle
of the activity of
this use case.
00:08:23.776 --> 00:08:25.826 A:middle
Over 50 percent of
the time is spent
00:08:25.826 --> 00:08:27.806 A:middle
at our most idle
state in the CPU.
00:08:27.936 --> 00:08:30.396 A:middle
So that indicates just how
quickly we can transition.
00:08:31.326 --> 00:08:32.556 A:middle
And finally near the end here is
00:08:32.556 --> 00:08:35.246 A:middle
when the data has finished
coming in - asynchronously
00:08:35.246 --> 00:08:37.366 A:middle
of course - and the
rendering has been finished.
00:08:37.576 --> 00:08:39.986 A:middle
And we've tried to move as
close to as much as idle
00:08:39.986 --> 00:08:41.645 A:middle
as possible when that's done.
00:08:42.456 --> 00:08:46.256 A:middle
Now let's compare this with
our Eyes Demo Application
00:08:46.846 --> 00:08:47.556 A:middle
that we just saw.
00:08:48.296 --> 00:08:51.416 A:middle
So you can see here, the Eyes
Application only lets the CPU
00:08:51.416 --> 00:08:54.376 A:middle
stay in its most idle state
about 75 percent of the time.
00:08:54.816 --> 00:08:58.106 A:middle
So that application - while
hidden behind another window -
00:08:58.436 --> 00:09:01.976 A:middle
is using significantly
more energy than Safari,
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:08:58.436 --> 00:09:01.976 A:middle
is using significantly
more energy than Safari,
00:09:01.976 --> 00:09:03.496 A:middle
rendering an entire webpage.
00:09:04.076 --> 00:09:06.886 A:middle
So even small applications
can have a large impact
00:09:06.986 --> 00:09:08.476 A:middle
on battery life and energy.
00:09:09.016 --> 00:09:13.386 A:middle
And you know, this is what
it was doing: polling.
00:09:14.056 --> 00:09:16.986 A:middle
The whole time, just polling,
checking where the mouse was,
00:09:17.076 --> 00:09:19.546 A:middle
redrawing where the eyes
needed to be and so forth.
00:09:20.036 --> 00:09:22.866 A:middle
And we can actually
do better than this.
00:09:23.076 --> 00:09:26.846 A:middle
So why would we exit the idle
state when there's work to do?
00:09:26.936 --> 00:09:28.976 A:middle
Well so for Safari, when
it was receiving data,
00:09:28.976 --> 00:09:30.026 A:middle
that's network activity.
00:09:30.026 --> 00:09:31.786 A:middle
That's a good reason to
wake up and do something.
00:09:32.276 --> 00:09:35.386 A:middle
Or when I was typing
Apple.com into the address bar,
00:09:35.686 --> 00:09:37.566 A:middle
that's another reason that
we might be doing some work.
00:09:38.136 --> 00:09:41.466 A:middle
We can actually transition
pretty fast between these states
00:09:41.466 --> 00:09:45.406 A:middle
such that disk I/O is a good
opportunity to save some energy.
00:09:46.696 --> 00:09:48.136 A:middle
And finally and most
importantly,
00:09:48.396 --> 00:09:50.316 A:middle
we exit idle because of timers.
00:09:50.396 --> 00:09:52.276 A:middle
And when we were
investigating this feature,
00:09:52.276 --> 00:09:56.306 A:middle
we found out that timers were
by far the Number 1 reason
00:09:56.306 --> 00:09:57.486 A:middle
to exit the idle state.
00:09:58.296 --> 00:10:00.116 A:middle
And that's because
there's so much API
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:09:58.296 --> 00:10:00.116 A:middle
And that's because
there's so much API
00:10:00.116 --> 00:10:01.586 A:middle
that actually involves timers.
00:10:02.046 --> 00:10:03.236 A:middle
That's everything
with a relative
00:10:03.236 --> 00:10:04.396 A:middle
or an absolute deadline.
00:10:05.506 --> 00:10:08.056 A:middle
So for example, NSTimer,
CF run loop timer,
00:10:08.206 --> 00:10:09.616 A:middle
dispatch source type timer.
00:10:09.876 --> 00:10:13.176 A:middle
These timers are both -- can
be both relative or absolute.
00:10:13.686 --> 00:10:18.216 A:middle
An API like sleep: let's
say we sleep for 1 second.
00:10:18.216 --> 00:10:21.426 A:middle
Well that means in 1 second, the
CPU has to exit the idle state,
00:10:21.466 --> 00:10:23.446 A:middle
wake up and continue
executing code.
00:10:24.016 --> 00:10:27.656 A:middle
It also includes
APIs with time outs
00:10:27.746 --> 00:10:30.096 A:middle
like pthread-cond-timedwait
and so forth.
00:10:31.346 --> 00:10:34.396 A:middle
And APIs built on top of
these like Perform Selector
00:10:34.396 --> 00:10:37.656 A:middle
with object after delay or
NS Run Loop run until date.
00:10:37.916 --> 00:10:38.876 A:middle
That last one?
00:10:39.076 --> 00:10:40.456 A:middle
Sometimes you see a
pattern of putting
00:10:40.456 --> 00:10:42.436 A:middle
that with a short timeout
inside of a wild loop.
00:10:42.776 --> 00:10:44.296 A:middle
So that would indicate
a lot of timers.
00:10:46.186 --> 00:10:47.306 A:middle
And many more.
00:10:49.506 --> 00:10:52.456 A:middle
So when developing AppNap,
we realized that in order
00:10:52.456 --> 00:10:55.166 A:middle
to effectively extend the
battery life of our laptops,
00:10:55.546 --> 00:10:57.466 A:middle
we needed to reduce