Blink Scheduler Update:
Scheduling Idle Tasks
May 13th, 2015
{rmcilroy, skyostil, alexclarke}@chromium.org
Scheduler basics
Before: one per-thread task queue
Task queue
Scheduler basics
Before: one per-thread task queue
Task�1
Scheduler basics
Before: one per-thread task queue
Task�1
Task�2
Scheduler basics
Before: one per-thread task queue
Task�1
Task�3
Task�2
Scheduler basics
Before: one per-thread task queue
Task�1
Task�3
Task�4
Task�2
Scheduler basics
Before: one per-thread task queue
Task�1
Task�3
Task�4
Task�2
Scheduler basics
Before: one per-thread task queue
Task�3
Task�4
Task�2
Scheduler basics
Before: one per-thread task queue
Task�3
Task�4
Task�2
Input
Task
Scheduler basics
Now: dedicated queues for different task types
Default task queue
Input task queue
Loading task queue
Scheduler basics
Now: dedicated queues for different task types
Task�2
Task�3
Task�1
Input
Task
Loading
Task
Scheduler basics
Now: dedicated queues for different task types
Task�2
Task�3
Task�1
Input
Task
Loading
Task
Blink
Scheduler
Scheduler basics
Now: dedicated queues for different task types
Task�2
Task�3
Task�1
Input
Task
Loading
Task
Blink
Scheduler
Scheduler basics
Now: dedicated queues for different task types
Task�2
Task�3
Task�1
Input
Task
Loading
Task
input state
render state
Blink
Scheduler
Scheduler basics
Now: dedicated queues for different task types
Magic
Task�2
Task�3
Task�1
Input
Task
Loading
Task
Blink
Scheduler
Scheduler basics
Now: dedicated queues for different task types
Task�2
Task�3
Task�1
Input
Task
Loading
Task
run
this
one
Blink
Scheduler
Scheduler basics
Now: dedicated queues for different task types
Task�2
Task�3
Task�1
Input
Task
Loading
Task
Blink
Scheduler
Scheduler basics
Now: dedicated queues for different task types
Task�2
Task�3
Task�1
Loading
Task
Blink
Scheduler
Scheduler basics
Tasks get posted by various clients
Task�2
Task�3
Task�1
Loading
Task
Compositor
Input router
Blink
...
Blink
Scheduler
Scheduling input & compositing
Scheduling input & compositing
Rule: Have I seen input in the last 100ms?
⇒ If so, prioritize input and compositor work
Scheduling input & compositing
Touchstart handling
touchstart
touchmove
ack
Paint
Scheduling input & compositing
Touchstart handling
touchstart
touchmove
ack
Paint
Loading task
Scheduling input & compositing
Touchstart handling
touchstart
touchmove
ack
Paint
delay
Loading task
Scheduling input & compositing
Touchstart handling: disallow loading tasks between touchstart and touchmove
touchstart
touchmove
ack
Paint
delay
Loading task
Scheduling input & compositing
first_gesture_scroll_update
Median ~41ms drops to ~25ms
-39%
mean_input_event_latency
Median ~50ms drops to ~42ms
-16%
queuing_durations
Median ~13ms drops to ~9ms
-30%
Scheduling loading tasks
HTML parser
Parse
main thread
background parser thread
Construct DOM
Parse
Scheduling loading tasks
HTML parser
Parse
main thread
background parser thread
Construct DOM
Input
Parse
Scheduling loading tasks
HTML parser
Parse
main thread
background parser thread
Parse
Scheduling loading tasks
HTML parser
Parse
main thread
background parser thread
Parse
Should yield?
Scheduling loading tasks
HTML parser
Parse
main thread
background parser thread
Input
Parse
Should yield?
Scheduling loading tasks
Yielding in
main thread
Scheduling timers
Scheduling timers
Timer
Timer
Timer
Timer
sorted by time
Message�Loop
Scheduling timers
Timer
Timer
Timer
Timer
sorted by time
Message�Loop
post
Scheduling timers
Timer
Timer
Timer
Timer
run all expired timers
Message�Loop
callback
Scheduling timers
Timer
Timer
Timer
Timer
Message�Loop
Should yield?
Scheduling timers
⇒ Turn timers into first
class tasks
Timer
Timer
Timer
Timer
Blink Scheduler
Demo video
Idle Tasks
Idle Periods
Compositor Task
Time
Input Task
Compositor Task
VSync
VSync
VSync
Other Task
Compositor Task
Idle Periods
Compositor Task
WillBegin
Frame
Time
Input Task
DidCommitFrame
WillBegin
Frame
Compositor Task
DidCommitFrame
Compositor Task
WillBegin
Frame
Other Task
Idle Periods
Compositor Task
WillBegin
Frame
Time
Input Task
DidCommitFrame
WillBegin
Frame
Compositor Task
DidCommitFrame
Compositor Task
WillBegin
Frame
Other Task
expected next frame begin
Idle Periods
Compositor Task
WillBegin
Frame
Time
Input Task
DidCommitFrame
idle period
WillBegin
Frame
Compositor Task
Compositor Task
WillBegin
Frame
idle period
Other Task
DidCommitFrame
Idle Periods
Compositor Task
WillBegin
Frame
Time
Input Task
Idle Task
DidCommitFrame
idle period
WillBegin
Frame
Compositor Task
Compositor Task
WillBegin
Frame
idle period
Other Task
DidCommitFrame
Idle task characteristics
Idle Periods
Compositor Task
Time
Input Task
Idle Task
idle period
Compositor Task
Compositor Task
idle period
Idle tasks return immediately due to too short deadline
Other Task
Repost Idle Task
V8 GC
Begin Frame
Commit Frame
16ms
V8 GC
Begin Frame
Commit Frame
16ms
JANK!
V8 GC Events
Scheduling Idle GC
Blink Scheduler
Deadline
GCIdleHandler
V8 Heap
Heap State
Mark Speed
% full
Alloc Load
Magic
Scavenge
Incremental Marking
Compaction
Nothing
Scheduling Idle GC
Idle Period
CC
commit
begin frame
Long Idle Periods
Normal Task
Idle Task
Idle period
Time
Non-idle period
PostDelayed(20ms)
VSync
Input
Long Idle Periods
Normal Task
Idle Task
Idle period
Time
Non-idle period
BeginFrameNotExpectedSoon
PostDelayed(20ms)
VSync
Input
Long Idle Periods
Normal Task
Idle Task
Idle period
Time
Non-idle period
PostDelayed(20ms)
20ms
deadline
VSync
Input
Long Idle Periods
Normal Task
Idle Task
Idle period
Time
Non-idle period
PostDelayed(20ms)
20ms
deadline
50ms
deadline
VSync
50ms
deadline
50ms
deadline
Input
Long Idle Periods
Normal Task
Idle Task
Idle period
Time
Non-idle period
PostDelayed(20ms)
20ms
deadline
50ms
deadline
VSync
50ms
deadline
50ms
deadline
Input
~20%�GC during idle
Nexus 5 - Key Mobile Sites (%GC in idle)
Desktop (MacOS 10.9) - Top 25 Sites (%GC in idle)
Long Idle Periods Enabled
Tweak GC heuristics (hpayer@)
~60%�GC during idle
Reduction in GC Atomic Pause
Long Idle Periods Enabled
Tweak GC heuristics (hpayer@) + Weak closure over approximation (jochen@)
Nexus 5 - Key Mobile Sites
Exposing idle time to the web
Starting prototype work on requestIdleFrame
doWork = function(deadline) {
while (performance.now() + estimatedTime < deadline) {
// Do work
}
if (hasMoreWork()) {
requestIdleFrame(doWork);
}
}
requestIdleFrame(doWork);
Demo of requestIdleFrame
Next steps
Questions?
Demo