1Samsung Open Source Group
How Servo Renders the Web
Adenilson Cavalcanti Msc.
Samsung Open Source Group
WebKit & Blink committer
W3C CSS WG member
2
MotivationMotivation
Rust and ServoRust and Servo
Concepts of Browser EnginesConcepts of Browser Engines
Servo High Level ArchitectureServo High Level Architecture
Anatomy of a CSS FeatureAnatomy of a CSS Feature
Summary
3Samsung Open Source Group
Motivation

All modern browser engines were
designed 15 years ago (KHTML, WebKit,
Gecko, Blink).

They fail to exploit full parallelism.

In both mobile and desktop more cores are
expected (but not faster CPUs).
4Samsung Open Source Group
Issues with Current Browser
Engines

Single-threaded

Javascript execution

Layout

Painting/rasterization

Security issues derived from C/C++

Huge code bases
5Samsung Open Source Group
Servo

New browser engine written in Rust

Parallel: layout, painting, selector matching

Targets performance and battery efficiency
6Samsung Open Source Group
Implementation Strategy

Rewrite layout, rendering, HTML/CSS
parsing, networking, core engine glue.

Reuse JavaScript engine, EME containers,
graphics library, fonts.

Bootstrap with OpenSSL, image libraries,
etc.
7Samsung Open Source Group
Servo Status

Over 120 CSS properties are supported

Rendering real sites nearly correct

Competitive to perf in benchmarks

2x-3x speedups on 4 cores
8Samsung Open Source Group
Rust
9Samsung Open Source Group
What is Rust?
https://www.youtube.com/watch?v=oKwub2OpsG4
10Samsung Open Source Group
The Case for Rust

It aims to solve some gruesome issues
with C/C++.

Be more expressive for hard tasks

Safety vs. performance: you can have
both!
11Samsung Open Source Group
Rust Features

Compiled language (uses llvm)

Memory safety

Concurrency

Parallelism
12Samsung Open Source Group
C++ vs. Rust
13
http://doc.rust-
lang.org/nightly/intro.html#ownership
C++ Example: Anything Wrong
Here?
Samsung Open Source Group
14
Run on Valgrind: Warnings
Samsung Open Source Group
15
Using gdb to Understand
What's Happening…
Samsung Open Source Group
16
AddressAddress
Address: 0x100103af0
Samsung Open Source Group
17
AddressAddress
Samsung Open Source Group
It Changed! 0x100103b10
18
Compiler warnings won’t catch it:
Ref Points to Old Address!
Samsung Open Source Group
19
Rust to the Rescue!
Samsung Open Source Group
20
Rust Stops Bugs From
Happening
Samsung Open Source Group
21Samsung Open Source Group

Ownership
– Exactly one variable “owns” an allocated value
– Ownership may be transferred (move)
– Ownership may be temporary (borrow)

Lifetime
– These variables’ scopes provide an upper bound on
how long that value lasts

Memory safety without overhead
– No garbage collector
– No SmartPointers
– No reference counting
22Samsung Open Source Group
Concepts of Browser
Engines
23
How a Browser Works…
Samsung Open Source Group
24
First OS
50 60 70 80 90 00 10 20
Books?
First
browser
OS books
time
Delay between a disruptive tech becoming widespread
and the textbooks being published
Reasons for Lack of Literature
Samsung Open Source Group
25
HTMLHTML
CSSCSS
JSJS
Loader /
Parser
Loader /
Parser
DOM
Tree
DOM
Tree
Script
Handler
Script
Handler
Browse
r
UI
Browse
r
UI
Layout* /
Renderin
g
Layout* /
Renderin
g
user-generated input
*Calculating layout is referred as Reflow (Gecko) or Attachment
(WebKit)
High Level Flow
Samsung Open Source Group
26
More details at: http://arxiv.org/abs/1505.07383
HTML
CSS
JS
DOM
Flow
Tree
Display
Lists
Layers
Final
Output
Parsing Styling
Layout
RenderingCompositing
ScriptScript
Servo High-Level Architecture
Samsung Open Source Group
27
ConstellationConstellation
RendererRenderer
LayoutLayoutScriptScript
Pipeline 1 (iframe 1)
RendererRenderer
LayoutLayoutScriptScript
Pipeline 2 (iframe 2)
Tab 1
RendererRenderer
LayoutLayoutScript
Pipeline 3 (iframe 3)
Servo Threading Architecture
Samsung Open Source Group
28Samsung Open Source Group
Servo Rendering Pipeline
Overview

Content (aka. Script):
– Creates and owns the DOM tree

Layout:
– Takes from content a snapshot of the DOM tree
– Calculates style (attachment), builds the flow tree
– Flow tree used to calculate the layout of nodes
– Layout of nodes used to build a display list
29Samsung Open Source Group
Servo Rendering Pipeline
Overview

Renderer:
– Receives a display list from layout
– Renders visible portions to one or more tiles in parallel

Compositor:
– Composites the tiles from the renderer
– Sends the final image to the screen for display
30Samsung Open Source Group
Blink/WebKit Differences

In Blink, layout will create a RenderTree
with RenderObjects that have geometric
information and know how to paint
themselves.

In Servo, layout will generate a FlowTree
and later DisplayLists are created from it.
31Samsung Open Source Group
Renderer and Compositor
●
Both the Renderer and Compositor are:
– Decoupled from Layout (separate threads)
– Designed for responsiveness
●
Compositor manages its memory.
– Screen is divided into a series of tiles:
– Rendered in parallel
– Required for mobile performance
●
Display lists are divided in sublists (i.e. stack
context):
– Contents can be retained on the GPU
– Rendered in parallel
32Samsung Open Source Group
Parallel Layout Challenges

HTML layout has complex dependencies:
– Inline element positioning
– Floating elements
– Vertical text
– Pagination

Each page is very different, making static
parallelism prediction difficult.
33
div
div
div
Queue
Parallel Layout
Samsung Open Source Group
34Samsung Open Source Group
Parallelism for Power Too

Force low-frequency CPU setting
– Above four cores, same end-to-end
performance as single core at high-
frequency
– BUT, 40% of the power usage
35
Parallelism Reduces Page
Appearance Time
Samsung Open Source Group
36Samsung Open Source Group
Servo Detailed Roadmap

https://github.com/servo/servo/wiki/Roadmap

Q2 2015
– Increase Servo quality - work on more sites
– Demonstrate superior end-to-end performance
– Mobile / embedded

2015
– Full Alpha-quality release
37Samsung Open Source Group
Contributions are Welcome!

Servo: github.com/mozilla/servo

Rust: github.com/mozilla/rust | rust-lang.org

#servo | #rust | #rust-internals @ irc.mozilla.org

dev-servo | rust-dev @ lists.mozilla.org

News: http://blog.servo.org/
38Samsung Open Source Group
Servo vs. Gecko: CNN
39Samsung Open Source Group
Servo vs. Gecko: Reddit
40Samsung Open Source Group
Thank You!

How Servo Renders the Web

  • 1.
    1Samsung Open SourceGroup How Servo Renders the Web Adenilson Cavalcanti Msc. Samsung Open Source Group WebKit & Blink committer W3C CSS WG member
  • 2.
    2 MotivationMotivation Rust and ServoRustand Servo Concepts of Browser EnginesConcepts of Browser Engines Servo High Level ArchitectureServo High Level Architecture Anatomy of a CSS FeatureAnatomy of a CSS Feature Summary
  • 3.
    3Samsung Open SourceGroup Motivation  All modern browser engines were designed 15 years ago (KHTML, WebKit, Gecko, Blink).  They fail to exploit full parallelism.  In both mobile and desktop more cores are expected (but not faster CPUs).
  • 4.
    4Samsung Open SourceGroup Issues with Current Browser Engines  Single-threaded  Javascript execution  Layout  Painting/rasterization  Security issues derived from C/C++  Huge code bases
  • 5.
    5Samsung Open SourceGroup Servo  New browser engine written in Rust  Parallel: layout, painting, selector matching  Targets performance and battery efficiency
  • 6.
    6Samsung Open SourceGroup Implementation Strategy  Rewrite layout, rendering, HTML/CSS parsing, networking, core engine glue.  Reuse JavaScript engine, EME containers, graphics library, fonts.  Bootstrap with OpenSSL, image libraries, etc.
  • 7.
    7Samsung Open SourceGroup Servo Status  Over 120 CSS properties are supported  Rendering real sites nearly correct  Competitive to perf in benchmarks  2x-3x speedups on 4 cores
  • 8.
  • 9.
    9Samsung Open SourceGroup What is Rust? https://www.youtube.com/watch?v=oKwub2OpsG4
  • 10.
    10Samsung Open SourceGroup The Case for Rust  It aims to solve some gruesome issues with C/C++.  Be more expressive for hard tasks  Safety vs. performance: you can have both!
  • 11.
    11Samsung Open SourceGroup Rust Features  Compiled language (uses llvm)  Memory safety  Concurrency  Parallelism
  • 12.
    12Samsung Open SourceGroup C++ vs. Rust
  • 13.
  • 14.
    14 Run on Valgrind:Warnings Samsung Open Source Group
  • 15.
    15 Using gdb toUnderstand What's Happening… Samsung Open Source Group
  • 16.
  • 17.
    17 AddressAddress Samsung Open SourceGroup It Changed! 0x100103b10
  • 18.
    18 Compiler warnings won’tcatch it: Ref Points to Old Address! Samsung Open Source Group
  • 19.
    19 Rust to theRescue! Samsung Open Source Group
  • 20.
    20 Rust Stops BugsFrom Happening Samsung Open Source Group
  • 21.
    21Samsung Open SourceGroup  Ownership – Exactly one variable “owns” an allocated value – Ownership may be transferred (move) – Ownership may be temporary (borrow)  Lifetime – These variables’ scopes provide an upper bound on how long that value lasts  Memory safety without overhead – No garbage collector – No SmartPointers – No reference counting
  • 22.
    22Samsung Open SourceGroup Concepts of Browser Engines
  • 23.
    23 How a BrowserWorks… Samsung Open Source Group
  • 24.
    24 First OS 50 6070 80 90 00 10 20 Books? First browser OS books time Delay between a disruptive tech becoming widespread and the textbooks being published Reasons for Lack of Literature Samsung Open Source Group
  • 25.
    25 HTMLHTML CSSCSS JSJS Loader / Parser Loader / Parser DOM Tree DOM Tree Script Handler Script Handler Browse r UI Browse r UI Layout*/ Renderin g Layout* / Renderin g user-generated input *Calculating layout is referred as Reflow (Gecko) or Attachment (WebKit) High Level Flow Samsung Open Source Group
  • 26.
    26 More details at:http://arxiv.org/abs/1505.07383 HTML CSS JS DOM Flow Tree Display Lists Layers Final Output Parsing Styling Layout RenderingCompositing ScriptScript Servo High-Level Architecture Samsung Open Source Group
  • 27.
    27 ConstellationConstellation RendererRenderer LayoutLayoutScriptScript Pipeline 1 (iframe1) RendererRenderer LayoutLayoutScriptScript Pipeline 2 (iframe 2) Tab 1 RendererRenderer LayoutLayoutScript Pipeline 3 (iframe 3) Servo Threading Architecture Samsung Open Source Group
  • 28.
    28Samsung Open SourceGroup Servo Rendering Pipeline Overview  Content (aka. Script): – Creates and owns the DOM tree  Layout: – Takes from content a snapshot of the DOM tree – Calculates style (attachment), builds the flow tree – Flow tree used to calculate the layout of nodes – Layout of nodes used to build a display list
  • 29.
    29Samsung Open SourceGroup Servo Rendering Pipeline Overview  Renderer: – Receives a display list from layout – Renders visible portions to one or more tiles in parallel  Compositor: – Composites the tiles from the renderer – Sends the final image to the screen for display
  • 30.
    30Samsung Open SourceGroup Blink/WebKit Differences  In Blink, layout will create a RenderTree with RenderObjects that have geometric information and know how to paint themselves.  In Servo, layout will generate a FlowTree and later DisplayLists are created from it.
  • 31.
    31Samsung Open SourceGroup Renderer and Compositor ● Both the Renderer and Compositor are: – Decoupled from Layout (separate threads) – Designed for responsiveness ● Compositor manages its memory. – Screen is divided into a series of tiles: – Rendered in parallel – Required for mobile performance ● Display lists are divided in sublists (i.e. stack context): – Contents can be retained on the GPU – Rendered in parallel
  • 32.
    32Samsung Open SourceGroup Parallel Layout Challenges  HTML layout has complex dependencies: – Inline element positioning – Floating elements – Vertical text – Pagination  Each page is very different, making static parallelism prediction difficult.
  • 33.
  • 34.
    34Samsung Open SourceGroup Parallelism for Power Too  Force low-frequency CPU setting – Above four cores, same end-to-end performance as single core at high- frequency – BUT, 40% of the power usage
  • 35.
    35 Parallelism Reduces Page AppearanceTime Samsung Open Source Group
  • 36.
    36Samsung Open SourceGroup Servo Detailed Roadmap  https://github.com/servo/servo/wiki/Roadmap  Q2 2015 – Increase Servo quality - work on more sites – Demonstrate superior end-to-end performance – Mobile / embedded  2015 – Full Alpha-quality release
  • 37.
    37Samsung Open SourceGroup Contributions are Welcome!  Servo: github.com/mozilla/servo  Rust: github.com/mozilla/rust | rust-lang.org  #servo | #rust | #rust-internals @ irc.mozilla.org  dev-servo | rust-dev @ lists.mozilla.org  News: http://blog.servo.org/
  • 38.
    38Samsung Open SourceGroup Servo vs. Gecko: CNN
  • 39.
    39Samsung Open SourceGroup Servo vs. Gecko: Reddit
  • 40.
    40Samsung Open SourceGroup Thank You!