Servo is a new prototype web browser layout engine written in Rust that was launched by Mozilla in 2012 with a new architecture to achieve high parallelism on components like layout and painting. The current supported CSS properties allow Servo to be mostly operational on static sites like Wikipedia and GitHub, with a surprisingly small code footprint.
The objective of this talk is to describe its architecture in high level, source code organization and how to get started hacking and contributing to Servo. The implementation of a visual CSS feature will be explained as also considerations about Servo future roadmap.
Each tab in servo is represented by a lightweight task thread that implements the Constellation (name is historical). There is a separate thread that handles UI compositing not shown here. Up to this point, we are similar to current Webkit and future Gecko.
Within the page in that tab, there is a pipeline that implements the script, layout, and actual rendering. For each iframe, things get interesting. We have a pipeline that consists of three concurrent tasks. The script task handles loading the DOM and JavaScript engine. The layout task turns that into a tree of CSS boxes. The Renderer task turns that into tiles to be displayed on the screen. This architecture permits both parallelism that we didn’t have before and stability.
<animate> You can add another pipeline when you add another iframe. And a third iframe can be added, optionally sharing the script task, which can be required in order to support some Web features.
The biggest challenge is that HTML layout is really complicated. Inline elements, like text with various formatting, can require information from its neighbors to know its own position. Floating elements can either shift or even forcibly break (when they have a pinned location) a line in places that do not respect a sequential order of evaluating the DOM nodes.
We’re thinking of adding speculative parallelism, but it’s unclear if the extra costs (ability to back out) outweigh the parallelism gains. More evaluation to do here.
Assume we have a page with a body that has three divs, each of which has some text. A top-down traversal (e.g., computing widths) allows the three divs, red, blue, and white to each be rendered in parallel.
These are power numbers for the overall process. Biggest thing to note is that most of the power difference comes from the frequency change, not the number of active cores (not necessarily true on mobile).
The big take-away here is that you can save nearly 40% power usage without sacrificing time in this scenario simply by using parallelism and a lower CPU frequency.