how servo renders the web

43
1 © 2014 Samsung Electronics Co. Open Source Group – Samsung Research America (Silicon Valley) Adenilson Cavalcanti BSc MSc WebKit & Blink committer W3C CSS WG member How Servo renders the Web

Upload: adenilson-cavalcanti

Post on 14-Apr-2017

253 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: How Servo Renders the Web

1 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Adenilson CavalcantiBSc MSc

WebKit & Blink committerW3C CSS WG member

How Servo renders the Web

Page 2: How Servo Renders the Web

2Open Source Group – Samsung Research America (Silicon Valley) © 2014 Samsung Electronics Co.

Summary

Motivation

Rust and Servo

Concepts of Browser engines

Servo high level architecture

Anatomy of a CSS feature

Page 3: How Servo Renders the Web

3 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

• All modern browser engines were de-signed 15 years ago (KHTML, WebKit, Gecko, Blink).

• They fail to exploit full parallelism.• Both in mobile and desktop we expect

more cores (but not faster clocked CPUs).

Motivation

Page 4: How Servo Renders the Web

4 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

• Single-threaded:• Javascript execution• Layout• Painting/rasterization

• Security issues derived from C/C++.• Huge code bases.

Issues of current browser en-gines

Page 5: How Servo Renders the Web

5 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

• New browser engine written in Rust.

• Parallel: layout, painting, selec-tor matching.

• Targeting performance and bat-tery saving.

Servo

Page 6: How Servo Renders the Web

6 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Demo

Running servo.

Page 7: How Servo Renders the Web

7 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

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.

Page 8: How Servo Renders the Web

8 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

• Over 120 CSS properties are supported.

• Rendering real sites near cor-rectly.

• Competitive perf in bench-marks.

• 2x-3x speedups on 4 cores.

Servo status

Page 9: How Servo Renders the Web

9 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Rust

Page 10: How Servo Renders the Web

10 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

What is Rust?

https://www.youtube.com/watch?v=oKwub2OpsG4

Page 11: How Servo Renders the Web

11 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Why Rust?

• It aims to solve some grue-some issues in C/C++.

• Be more expressive for hard tasks.

• Safety X performance: have both!

The case for Rust

Page 12: How Servo Renders the Web

12 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

• Compiled language (uses llvm).

• Memory safety.• Concurrency.• Parallelism.

Rust features

Page 13: How Servo Renders the Web

13 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

C++ x Rust

Page 14: How Servo Renders the Web

14 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

C++ example: anything wrong here?

http://doc.rust-lang.org/nightly/intro.html#ownership

Page 15: How Servo Renders the Web

15 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Run on valgrind: warnings

Page 16: How Servo Renders the Web

16 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Using gdb to understand what is happening…

Page 17: How Servo Renders the Web

17 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Address: 0x100103af0

Ad-dress

Page 18: How Servo Renders the Web

18 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Change! Now: 0x100103b10

Ad-dress

Page 19: How Servo Renders the Web

19 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Ref points to old address!

Compiler warnings won’t catch it:

Page 20: How Servo Renders the Web

20 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Rust to the rescue!

Page 21: How Servo Renders the Web

21 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Rust stops bugs from happening.

Page 22: How Servo Renders the Web

22 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

• 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 GC– No SmartPointers– No reference counting

Page 23: How Servo Renders the Web

23 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Concepts of browser engines

Page 24: How Servo Renders the Web

24 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

How a browser works…

Page 25: How Servo Renders the Web

25 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Reasons for lack of literature

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

Page 26: How Servo Renders the Web

26 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

High level flow

HTML

CSS

JS

Loader /Parser

DOMTree

ScriptHandler

BrowserUI

Layout* /Render-

ing

user-generated input

*Calculating layout is referred as Reflow (Gecko) or Attachment (WebKit)

Page 27: How Servo Renders the Web

27 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Servo high-level architecture

More details at: http://arxiv.org/abs/1505.07383

HTMLCSSJS

DOM FlowTree

DisplayListsLayersFinal

Output

Parsing Styling

Layout

RenderingCompositing

ScriptScript

Page 28: How Servo Renders the Web

28 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Servo threading architecture

Constella-tion

Renderer

Lay-outScript

Pipeline 1 (iframe 1)

Renderer

Lay-outScript

Pipeline 2 (iframe 2)

Tab 1

Renderer

Lay-outScript

Pipeline 3 (iframe 3)

Page 29: How Servo Renders the Web

29 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

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), building the flow tree• Flow tree used to calculate the layout of nodes• Layout of nodes used to build a display list

• 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

Page 30: How Servo Renders the Web

30 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

• In Blink, layout will create a RenderTree with RenderObjects that have geomet-ric information and know how to paint themselves.

• In Servo, layout will generate a FlowTree and later DisplayLists are cre-ated from it.

Blink/WebKit Differences

Page 31: How Servo Renders the Web

31 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Renderer and Compositor• Both Renderer and Compositor are:• Decoupled from Layout (separate threads)• Design aimed at 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 con-text):• Contents can be retained on the GPU• Rendered in parallel

Page 32: How Servo Renders the Web

32 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Demo

• Dump flowtree, display lists.• Parallel layout, parallel painting.

Page 33: How Servo Renders the Web

33 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

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.

Page 34: How Servo Renders the Web

34 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Parallel layoutdivdivdiv

Queue

Page 35: How Servo Renders the Web

36 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Parallelism reduces page appearance time

Page 36: How Servo Renders the Web

37 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

CSS filter blur

Code analysis.

Page 37: How Servo Renders the Web

38 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

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

Page 38: How Servo Renders the Web

39 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Contributing to Servo & Rust

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/

Page 39: How Servo Renders the Web

40 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Special thanks

• Samsung OSG (OpenSource Group).

• Lars Bergstrom (Mozilla).

• Bruno Abinader (Mapbox).

Page 40: How Servo Renders the Web

41Open Source Group – Samsung Research America (Silicon Valley) © 2014 Samsung Electronics Co.

Questions?

Page 41: How Servo Renders the Web

Thank you.

42Open Source Group – Samsung Research America (Silicon Valley) © 2014 Samsung Electronics Co.

Page 42: How Servo Renders the Web

43 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Servo vs. Gecko (CNN)

Page 43: How Servo Renders the Web

44 © 2014 Samsung Electronics Co.Open Source Group – Samsung Research America (Silicon Valley)

Servo vs. Gecko (reddit)