49
웹브라우저 엔진 김효 ([email protected]) 시스템스컴퓨팅G / NAVER LABS 2015-2

[D2 campus seminar]웹브라우저 엔진

Embed Size (px)

Citation preview

Page 1: [D2 campus seminar]웹브라우저 엔진

웹브라우저 엔진

김효 ([email protected])

시스템스컴퓨팅G / NAVER LABS

2015-2

Page 2: [D2 campus seminar]웹브라우저 엔진

Hyo Kim ([email protected], [email protected])

Linux Kernel/Cluster : 5 Years

Distributed File System, Database, NoSQL Engine : 5 Years

Browser Engine : 5 Years

Naver Web Engine Lead

Page 3: [D2 campus seminar]웹브라우저 엔진

3

Contents

Browser Engine

How Browser Works

Advanced Rendering Technology

How to Improve Rendering Performance

JavaScript Engine

Naver Labs & Developers

Page 4: [D2 campus seminar]웹브라우저 엔진

Browser Engine

Page 5: [D2 campus seminar]웹브라우저 엔진

5

HTML5

Page 6: [D2 campus seminar]웹브라우저 엔진

6

HTML5

On 28 October 2014, HTML5 was released as a W3C Recommendation

Page 7: [D2 campus seminar]웹브라우저 엔진

7

HTML5

Page 8: [D2 campus seminar]웹브라우저 엔진

8

Evolution of the Worldwide Browser Landscape

Page 9: [D2 campus seminar]웹브라우저 엔진

9

Desktop browser trend

Page 10: [D2 campus seminar]웹브라우저 엔진

10

Mobile browser trend

Page 11: [D2 campus seminar]웹브라우저 엔진

11

Major Browser’s Rendering Engine

SERVO

Page 12: [D2 campus seminar]웹브라우저 엔진

12

Mobile browser trend

* Code wars - BCG

Page 13: [D2 campus seminar]웹브라우저 엔진

13

어디에 쓰이나?

Contents

App Engine

Browser

Devices Web OS

Browser Engine

Page 14: [D2 campus seminar]웹브라우저 엔진

How browsers work

Page 15: [D2 campus seminar]웹브라우저 엔진

15

Browser at High Level

Co

de C

ove

rag

e

10%

90%

UI

Browser Engine

Rendering Engine

Network I/O JavaScript

Engine Graphics

Stack

Data

Persiste

nce

Page 16: [D2 campus seminar]웹브라우저 엔진

16

<html> <head> <title> NAVER </title> </head> <body> <div> <h1> Hello </h1> <p> World </p> </div> </body> </html>

Summary of browser main flows.

Page 17: [D2 campus seminar]웹브라우저 엔진

17

Loader

Page 18: [D2 campus seminar]웹브라우저 엔진

18

DOM: Document Object Model - Document = HTML, well-formed XML - Object Model = Data + Method Standard way for accessing and manipulating documents.

+

HTML Parser : DOM

Page 19: [D2 campus seminar]웹브라우저 엔진

19

HEAD

TITLE

NAVER

BODY

DIV

H1 P

HTML

Hello World

<html> <head> <title> NAVER </title> </head> <body> <div> <h1> Hello </h1> <p> World </p> </div> </body> </html>

HTML Parser : Example

Page 20: [D2 campus seminar]웹브라우저 엔진

20

HTML

CSS

DOM Tree

Style Rules

Renderer Tree Lookup

Render Tree : Render Tree flows

Page 21: [D2 campus seminar]웹브라우저 엔진

21

HEAD

TITLE

NAVER

BODY

DIV

H1 P

HTML

Hello World

Block

Block

Block

Block Block

Inline Inline

Render Tree : Example

Page 22: [D2 campus seminar]웹브라우저 엔진

22

Render Tree : Visual formatting Model

< Relative Positioning > < Normal Flow >

< Block formatting context >

< Inline formatting context >

Page 23: [D2 campus seminar]웹브라우저 엔진

23

CSS layout reflow

Page 24: [D2 campus seminar]웹브라우저 엔진

24

Layout : Example

HEAD

TITLE

NAVER

BODY

DIV

H1 P

HTML

Hello World

Block

Block

Block

Block Block

Inline Inline

(0, 0, 1024, 768)

(0, 0, 1024, 768)

(0, 0, 1024, 55)

(10, 20, 1024, 37) (10, 80, 1024, 18)

Page 25: [D2 campus seminar]웹브라우저 엔진

25

Paint

Block (html)

Block (body)

Block (div)

Block (h1) Block (p)

Inline (hello) Inline (world)

(0, 0, 1024, 768)

(0, 0, 1024, 768)

(0, 0, 1024, 55)

(10, 20, 1024, 37) (10, 80, 1024, 18) 1024

768 <div>

Page 26: [D2 campus seminar]웹브라우저 엔진

26

CSS Z-order layer

Page 27: [D2 campus seminar]웹브라우저 엔진

27

Summary of browser main flows.

DOM Node

DOM Node

DOM Node

DOM Node

DOM Node

DOM Node

Render Object

Render Object

Render Object

Render Object

Render Object

Render Object

Render Layer

Render Layer

Render Layer

Render Layer

HTML

CSS Style Sheet

HTML Parser

CSS Parser

DOM Tree

Style Rule

attach() Render

Tree

Layout

Painting Display

Parsing Layouting Painting

DOM Tree Render Tree

Loading

Platform drawing callback.

Page 28: [D2 campus seminar]웹브라우저 엔진

Advanced Rendering Technology

Page 29: [D2 campus seminar]웹브라우저 엔진

29

1. Non-composited SW rendering (Traditional)

2. Composited SW rendering

3. Composited GPU rendering

Types of rendering path

Page 30: [D2 campus seminar]웹브라우저 엔진

30

Layers in WebKit

1. It's the root object for the page. <html>

2. CSS position properties (relative, absolute or a

transform)

3. It is transparent

4. Has overflow, an alpha mask or reflection

5. Has a CSS filter

6. <canvas>

7. <video>

Page 31: [D2 campus seminar]웹브라우저 엔진

31

Rendering Path : Hardware Rendering Path

1. 각 Layer 별 bitmap을 생성 (Render Layer traversing)

2. Textures upload into Video memory

3. Compositor에서 Layer 순서에 맞게 Texture를 drawing하여 화면에 Update

Page 32: [D2 campus seminar]웹브라우저 엔진

32

Rendering (1/2): Ideal

Page 33: [D2 campus seminar]웹브라우저 엔진

33

Rendering (2/2): Real

Page 34: [D2 campus seminar]웹브라우저 엔진

34

Threaded Compositor

Page 35: [D2 campus seminar]웹브라우저 엔진

35

Threaded Rasterization

Page 36: [D2 campus seminar]웹브라우저 엔진

How to improve rendering performance

Page 37: [D2 campus seminar]웹브라우저 엔진

37

layout & painting

• Layout : 배치를 바꾸는 것

• Painting : 그리는 것

• Web engine의 주요 병목 지점

• Web engine 개발자는 layout과 painting이

– 가능하면 발생하지 않도록 하고,

– 빠르게 하고,

– 영향을 최소화해야 한다.

Page 38: [D2 campus seminar]웹브라우저 엔진

38

Understanding Dev Tools

Page 39: [D2 campus seminar]웹브라우저 엔진

39

https://docs.google.com/spreadsheet/pub?key=0ArK1Uipy0SbDdHVLc1ozTFlja1dhb25QNGhJMXN5MXc&single=true&gid=0&output=html

CSS properties by style operation required

Page 40: [D2 campus seminar]웹브라우저 엔진

40

가능하면 발생하지 않도록

• left/top에 의한 이동은 transform/translate을 이용

• show/hide는 alpha값에 의한 opacity를 이용

Use layers to improve performance

http://sculove.github.io/slides/improveBrowserRendering/#/8

최적의 layer를 구성한다.

Page 41: [D2 campus seminar]웹브라우저 엔진

41

Use layers to improve performance

< Multi layer mode using translate3d>

< Single layer mode>

Page 42: [D2 campus seminar]웹브라우저 엔진

42

Tiling

• Viewport와 covered rect에 걸쳐있는 tile들만 paint, texture upload.

• Tile의 크기(width * height)는 가변적이며, 2의 배수 단위를 사용 – Chrome의 경우 256 * 256 을 주로 사용

• 준비되지 않은 Tile이 필요할 때에는 해당 Tile을 생성, paint, upload 해야 함

• Tile Management (일종의 메모리 관리)

Page 43: [D2 campus seminar]웹브라우저 엔진

JavaScript Engine

Page 44: [D2 campus seminar]웹브라우저 엔진

44

Java Script Engine

Source Code Parser Syntax Tree

Bytecode Generator

Bytecode

JIT Compiler Machine Code

Execution

Loader

Parser

DOM

Java Script

Page 45: [D2 campus seminar]웹브라우저 엔진

45

JavaScriptCore FLT JIT optimization

JS Source

Interpret with LLInt

Compile with Baseline

Compile with DFG

Execute Baseline code

Execute DFG code

Execute FTL code

Compile with FTL collect LLInt

profiling

collect Baseline profiling :

value profiles and inline caches

collect DFG profiling :

context-sensitive profiling for any inlined functions

code ran for a while trigger DFG compilation

trigger FTL compilation

Page 46: [D2 campus seminar]웹브라우저 엔진

46

Asm.js

• AOT(ahead-of-time) compiling • use asm • JavaScript subset

Page 47: [D2 campus seminar]웹브라우저 엔진

기밀

47 / 파워포인트 문서 사용 안내

Asm.js : Demo

Page 48: [D2 campus seminar]웹브라우저 엔진

48

Page 49: [D2 campus seminar]웹브라우저 엔진

49