Scheduling tasks intelligently for optimized performance
Earlier this month, Chrome began utilizing new techniques to get pages in front of users faster. That's an important piece of the performance story, but it's just one – what about once the page has loaded fully? That's when users want pages to animate smoothly and react quickly to their scrolls and clicks. Chrome 41 included a task scheduler for Chrome's rendering engine that ensures those high-priority tasks are handled immediately, making Chrome feel snappier and run closer to a smooth 60 frames per second.
Given that ambitious goal, Chrome has just milliseconds to produce every frame. But painting graphics to the screen isn't all that Chrome does, and there can be several different tasks contending for a single processor core. Historically Chrome handled execution of tasks, such as animating an image, responding to a click, or doing some memory operations, the same way that a bank handles a queue of customers: the first one line in is the first one handled. While this is simple and straightforward, it's not always the best for optimal performance. An urgent task, such as painting the next frame to the screen, might be added to the end of a long queue of pending tasks. The 60 frames per second goal would be lost.
Starting in Chrome 41, we've created a task scheduler integrated into the Blink rendering engine. The scheduler is capable of evaluating pending tasks and reordering them so that the most urgent tasks, such as animating and responding to a user's action, are prioritized ahead of others. Lower priority tasks, such as clearing out unused memory, are delayed until the processor has available time. In practice, this results in up to a 40% higher responsiveness to user input when Chrome is working hard to draw frames.
However, even the most advanced scheduler can't properly queue up tasks without knowing what's coming in the future. To address this, the Blink scheduler is also integrated with Chrome's graphics engine, which has precise knowledge of when Chrome will need to deprioritize other tasks in order to paint graphics to the screen. This allows the scheduler to consider lower priority tasks and schedule only those tasks that fit nicely into the otherwise "idle" time before Chrome needs to draw another frame. These tasks are handled essentially for free, with no impact on the smooth, 60 frames-per-second animations.
The latest version of Chrome scrolling a particularly challenging website, with the scheduler enabled (left) and disabled (right).
These changes demonstrate that performance isn't just about doing things faster – it's also about doing things smarter, in the right order, and at the right time. Stay tuned for more updates about how we're using Chrome's scheduler to push the bounds of performance.
Posted by Sami Kyostila and Ross McIlroy, Senior Task Masters