How browser engines work?

75
HOW BROWSER ENGINES WORK? Anthony Ricaud, @rik24d

Transcript of How browser engines work?

Page 1: How browser engines work?

HOW BROWSER ENGINES WORK?

Anthony Ricaud, @rik24d

Page 2: How browser engines work?

PARDON MY FRENCH

http://www.flickr.com/photos/nitot/6537065859/

Page 4: How browser engines work?

THIS IS ONLY AN INTRODUCTION

Page 5: How browser engines work?

WHO ?

- Web developer at Mozilla but

- 2 patches in Firefox

- 23 in WebKit

Page 6: How browser engines work?

STANDING ON THE SHOULDERS OF GIANTS

- Robert O’Callahan, Boris Zbarsky, David Baron (Mozilla)

- Dave Hyatt, Simon Fraser (Apple)

- Paul Irish, Alex Russell, Tony Gentilcore, (Google)

- Anne Van Kersteren (Opera)

- Nicholas Zakas (ex-Yahoo), Eric Law (Microsoft)

Page 7: How browser engines work?

STANDING ON THE SHOULDERS OF GIANTS

- List of documents to prepare this talk

- http://ricaud.me/nav-marche

Page 8: How browser engines work?
Page 9: How browser engines work?

CHROME

Page 10: How browser engines work?

CONTENT

Page 11: How browser engines work?

IT’S COMPLEX

Page 12: How browser engines work?

IT’S COMPLEX

URL parser

Cache system

Network stackCookies

Databases

Painting

JS Engine

DOM Bindings

Accessibility stack

Font rendering

Image decoding Downloading

PluginsNative themesScrolling

Page 13: How browser engines work?

PRESTO TRIDENTGECKO WEBKIT

Page 14: How browser engines work?

PRESTO TRIDENTGECKO WEBKIT

Page 15: How browser engines work?

NEW REQUEST

- Parse the URL : protocol, domain

- DNS requestwww.mozilla.org -> 63.245.208.161

- Open TCP connection, send HTTP request

Page 16: How browser engines work?

SERVER RESPONSEHTTP/1.1 200 OKContent-Type: application/xhtml+xml

Page 17: How browser engines work?

SERVER RESPONSEHTTP/1.1 200 OKContent-Type: application/xhtml+xml

XML MODE

Page 18: How browser engines work?

SERVER RESPONSEHTTP/1.1 200 OKContent-Type: application/xhtml+xml

XML MODE

Page 19: How browser engines work?

SERVER RESPONSEHTTP/1.1 200 OKContent-Type: application/xhtml+xml

XML MODE

Page 20: How browser engines work?

SERVER RESPONSEHTTP/1.1 200 OKContent-Type: application/xhtml+xmlContent-Type: text/html

<html>

Page 21: How browser engines work?

SERVER RESPONSEHTTP/1.1 200 OKContent-Type: application/xhtml+xmlContent-Type: text/html

<html>

QUIRKS MODE

Page 22: How browser engines work?

SERVER RESPONSEHTTP/1.1 200 OKContent-Type: application/xhtml+xmlContent-Type: text/html

<html>

QUIRKS MODE

Page 23: How browser engines work?

SERVER RESPONSEHTTP/1.1 200 OKContent-Type: application/xhtml+xmlContent-Type: text/html

<html>

QUIRKS MODE

Page 24: How browser engines work?

SERVER RESPONSEHTTP/1.1 200 OKContent-Type: application/xhtml+xmlContent-Type: text/html

<html><!doctype html><html>

Page 25: How browser engines work?

SERVER RESPONSEHTTP/1.1 200 OKContent-Type: application/xhtml+xmlContent-Type: text/html

<html><!doctype html><html>

STANDARDS MODE

Page 26: How browser engines work?

HTML5, HTML4, XHTML1.0, CSS3, ECMASCRIPT 5

Page 27: How browser engines work?

HTML5, HTML4, XHTML1.0, CSS3, ECMASCRIPT 5

THEY DON’T CARE

Page 28: How browser engines work?

<!doctype html><html> <head> <title>KISS</title> </head> <body> <div> <h1>BISOUS</h1> <p>Bonnes Idées Simples Ou Ultra Sensées.</p> </div> </body></html>

Page 29: How browser engines work?

HTML

HEAD BODY

TITLE DIV

H1 PKISS

BISOUSBONNES IDÉES

SIMPLES OU ULTRA SENSÉES.

Page 30: How browser engines work?

HTML

HEAD BODY

TITLE DIV

H1 PKISS

BISOUSBONNES IDÉES

SIMPLES OU ULTRA SENSÉES.

DOM TREE

Page 31: How browser engines work?

HTML

HEAD BODY

TITLE DIV

H1 PKISS

BISOUSBONNES IDÉES

SIMPLES OU ULTRA SENSÉES.

Page 32: How browser engines work?

HTML

HEAD BODY

TITLE DIV

H1 PKISS

BISOUSBONNES IDÉES

SIMPLES OU ULTRA SENSÉES.

Page 33: How browser engines work?

SUB-RESOURCES

Page 34: How browser engines work?

SUB-RESOURCES- Image

Page 35: How browser engines work?

SUB-RESOURCES- Image- Launch a download, non-blocking

Page 36: How browser engines work?

SUB-RESOURCES- Image- Launch a download, non-blocking- Runs an image decoder

Page 37: How browser engines work?

SUB-RESOURCES- Image- Launch a download, non-blocking- Runs an image decoder

- CSS

Page 38: How browser engines work?

SUB-RESOURCES- Image- Launch a download, non-blocking- Runs an image decoder

- CSS- Launch a download, non-blocking

Page 39: How browser engines work?

SUB-RESOURCES- Image- Launch a download, non-blocking- Runs an image decoder

- CSS- Launch a download, non-blocking- Then it gets interesting…

Page 40: How browser engines work?

CSS BUCKETS

ID OTHERSTAGNAMECLASS

Page 41: How browser engines work?

CSS BUCKETS

ID OTHERSTAGNAMECLASS

div

Page 42: How browser engines work?

CSS BUCKETS

ID OTHERSTAGNAMECLASS

div

Page 43: How browser engines work?

CSS BUCKETS

ID OTHERSTAGNAMECLASS

div

.item

Page 44: How browser engines work?

CSS BUCKETS

ID OTHERSTAGNAMECLASS

div.item

Page 45: How browser engines work?

CSS BUCKETS

ID OTHERSTAGNAMECLASS

div.item

#sidebar

Page 46: How browser engines work?

CSS BUCKETS

ID OTHERSTAGNAMECLASS

div.item#sidebar

Page 47: How browser engines work?

CSS BUCKETS

ID OTHERSTAGNAMECLASS

div.item#sidebar

div#sidebar

Page 48: How browser engines work?

CSS BUCKETS

ID OTHERSTAGNAMECLASS

div.item#sidebar

div#sidebar

Page 49: How browser engines work?

CSS BUCKETS

ID OTHERSTAGNAMECLASS

div.item#sidebar

div#sidebar

div p

Page 50: How browser engines work?

CSS BUCKETS

ID OTHERSTAGNAMECLASS

div.item#sidebar

div#sidebar div p

Page 51: How browser engines work?

CSS BUCKETS

ID OTHERSTAGNAMECLASS

div.item#sidebar

div#sidebar div p

:visited

Page 52: How browser engines work?

CSS BUCKETS

ID OTHERSTAGNAMECLASS

div.item#sidebar

div#sidebar div p

:visited

Page 53: How browser engines work?

DOM TREE + PARSING CSS

HTMLDOM Tree

CSSStyle Rules

Page 54: How browser engines work?

CSS MATCHINGBODY

DIV

P

DIVid="sidebar"

PP

DIVclass="item"

DIVclass="item"

DIVclass="item"

div.item#sidebardiv#sidebardiv pul pul > pbody > div p#sidebar p

Page 55: How browser engines work?

RENDER TREEHTML

HEAD BODY

TITLE DIV

H1 PKISS

BISOUS BONNES IDÉES SIMPLES OU

Page 56: How browser engines work?

RENDER TREEHTML

HEAD BODY

TITLE DIV

H1 PKISS

BISOUS BONNES IDÉES SIMPLES OU

Viewport

Block

Block

Scroll

Block

Block Block

TextText

Page 57: How browser engines work?

DOM TREE + RENDER TREE

HTMLDOM Tree

CSSStyle Rules

Render Tree

Page 58: How browser engines work?

A REFLOW OR LAYOUT

Page 59: How browser engines work?

A REFLOW OR LAYOUT

Page 60: How browser engines work?

HTMLDOM Tree

CSSStyle Rules

Render Tree Layout

Page 61: How browser engines work?

AND PAINTING

HTMLDOM Tree

CSSStyle Rules

Render Tree Layout Painting

Page 62: How browser engines work?

PAINT ?

Page 63: How browser engines work?

PAINT ?

- Used to be the CPU drawing everything

Page 64: How browser engines work?

PAINT ?

- Used to be the CPU drawing everything

- We’re giving more and more stuff to the GPU

Page 65: How browser engines work?

PAINT ?

- Used to be the CPU drawing everything

- We’re giving more and more stuff to the GPU

- Hardware acceleration

Page 66: How browser engines work?

SUB-RESOURCES- Image- Launch a download, non-blocking- Runs an image decoder

- CSS- Launch a download, non-blocking- Then it gets interesting…

Page 67: How browser engines work?

SUB-RESOURCES- Image- Launch a download, non-blocking- Runs an image decoder

- CSS- Launch a download, non-blocking- Then it gets interesting…

- JS- Launch a download, almost blocking

Page 68: How browser engines work?

JAVASCRIPT

- JS and DOM are different

- DOM = slow

- Be careful about triggering unnecessary reflows

Page 69: How browser engines work?

HTMLDOM Tree

CSSStyle Rules

Render Tree Layout

Page 70: How browser engines work?

POTENTIAL REFLOW

HTMLDOM Tree

CSSStyle Rules

Render Tree Layout Painting

Page 71: How browser engines work?

NEW JAVASCRIPT ENGINES

Page 72: How browser engines work?

NEW JAVASCRIPT ENGINES

- Storing info about the code to compute it only once

Page 74: How browser engines work?

- http://ricaud.me/nav-marche

- @rik24d

- [email protected]

- Merci Mauriz

Page 75: How browser engines work?

QUESTIONS ?

- http://ricaud.me/nav-marche

- @rik24d

- [email protected]

- Merci Mauriz