Slide 1

Slide 1 text

Presented by Liang Gong 2016 Spring Polaris: Faster Page Loads Using Fine-grained Dependency Tracking Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Ravi Netravali, Ameesh Goyal, James Mickens, Hari Balakrishnan To appear in NSDI’16

Slide 2

Slide 2 text

2 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Overview • Motivation: Reduce web page’s loading time.

Slide 3

Slide 3 text

3 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Overview • Motivation: Reduce web page’s loading time. • Main Approach: • Analyze the dependency graph of resources loaded by the web page.

Slide 4

Slide 4 text

4 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Overview • Motivation: Reduce web page’s loading time. • Main Approach: • Analyze the dependency graph of resources loaded by the web page. • Use a dynamic scheduler to aggressively fetch resources to minimize waiting.

Slide 5

Slide 5 text

5 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Overview • Motivation: Reduce web page’s loading time. • Main Approach: • Analyze the dependency graph of resources loaded by the web page. • Use a dynamic scheduler to aggressively fetch resources to minimize waiting. • Evaluation: decreases page load time by 34% at the median. • top 200 websites ranked by Alexa

Slide 6

Slide 6 text

6 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Loading a Web Page • Modern browsers halt the parsing and rendering of the page when encountering a tag.

Slide 7

Slide 7 text

7 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Loading a Web Page • Modern browsers halt the parsing and rendering of the page when encountering a tag. – The evaluation of first.js may alter the downstream HTML.

Slide 8

Slide 8 text

8 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Loading a Web Page • Modern browsers halt the parsing and rendering of the page when encountering a tag. – The evaluation of first.js may alter the downstream HTML. – first.js may define js state used by second.js.

Slide 9

Slide 9 text

9 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Loading a Web Page • Modern browsers halt the parsing and rendering of the page when encountering a tag. – The evaluation of first.js may alter the downstream HTML. – first.js may define js state used by second.js. – Scripts are fetched synchronously.

Slide 10

Slide 10 text

10 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Motivation • If first.js and second.js do not modify mutually observable state, they can be downloaded and evaluated in any order.

Slide 11

Slide 11 text

11 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Motivation • If first.js and second.js do not modify mutually observable state, they can be downloaded and evaluated in any order. – GL: Sometimes people may want to control the order though. – GL: sounds like data-race detection in web.

Slide 12

Slide 12 text

12 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Approach Overview • Server Side: track dataflow by instrumentation  construct fine-grained dependency graph. • Client Side: A dynamic scheduler uses the dependency graph to reduce load time. Scout Polaris

Slide 13

Slide 13 text

13 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Dependency Graph (Tree) • Traditional dependency graph: lexical dependency

Slide 14

Slide 14 text

14 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Dependency Graph (Tree) • Traditional dependency graph: lexical dependency • CSS blocks JS script tags • JS code may read CSS style properties • JS script tags blocks HTML parsing • JS may change the downstream HTML • JS script tags block JS script tags • Two JS scripts may have data-race • CSS blocks CSS • If two css files update the same rule, the last writer wins.

Slide 15

Slide 15 text

15 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. More Accurate Dependency Graph • New dependency graph: data-race dependency • Write/Read, Read/Write, Write/Write

Slide 16

Slide 16 text

16 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Capture Dependency Via Instrumentation • Tracking JavaScript heap dependencies – Source-level instrumentation – Proxy API provided by browsers • Tracking DOM dependencies

Slide 17

Slide 17 text

17 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Tracking JS Heap Dependencies • Step 1: Rewriting Global variable references are changed to fully qualified name: x = 1  window.x = 1 But you cannot redefine the window object: window = Proxy(window, handler); Solution: (function () { var alias_window = Proxy(window, handler); return function () { alias_window.x = 1; … } })();

Slide 18

Slide 18 text

18 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Tracking JS Heap Dependencies • Step 1: Rewriting • Step 2: Recursive Proxying • each object is tagged with an integer id • When a proxy does get-field operation: – If return value is not a proxy, wrap it with proxy. – window.x.y.z will return a proxy object.

Slide 19

Slide 19 text

19 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Tracking DOM Dependencies • Step 1: Rewriting document  window.document • Step 2: Recursive Proxy • Intercept and create proxy for all objects queried from DOM. • Identifies DOM nodes by their paths in the DOM tree.

Slide 20

Slide 20 text

20 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Tracking DOM Dependencies • Each CSS tag can also modify the DOM (the style property of the DOM elements). • • Model each of those tags as reading all of the DOM nodes that are above it in the HTML and writing those DOM nodes with new style information. • Solution: insert inline script tags before each of those CSS tags • … •

Slide 21

Slide 21 text

21 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Approach Overview • Server Side: track dataflow by instrumentation  construct fine-grained dependency graph. • Client Side: A dynamic scheduler uses the dependency graph to reduce load time. Scout Polaris

Slide 22

Slide 22 text

22 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Scheduler on the Client Side • Identify the dynamic critical path. Request objects in an order that minimize the total loading time. • Assumption: Each object’s loading time is a constant.

Slide 23

Slide 23 text

23 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Evaluation • round-trip time (RTT) is the length of time it takes for a signal to be sent plus the length of time it takes for an acknowledgment of that signal to be received.

Slide 24

Slide 24 text

24 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Limitations • Eval is not supported. • What about closure, how to instrument closure using web proxy? • Unknown native API? • Modify the behavior of Math.random to eliminate non-determinism • For each client devise, a separate dependency graph must be generated. – Since the page loading behavior maybe client-specific – Also dynamic webpage will generate content dynamically, according to user’s cookie and the content in database. It is impossible to run everything ahead of time. • On the client-side, polaris uses XMLHttpRequests to dynamically fetch objects. To evaluate a JavaScript file, the scheduler uses the eval function. • Assume each object’s loading time is a constant. All improvements obtained are based on that assumption.

Slide 25

Slide 25 text

25 Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. Motivation • If first.js and second.js do not modify mutually observable state, they can be downloaded and evaluated in any order. – GL: Sometimes people may want to control the order though. – GL: sounds like data-race detection in web. – GL: if second.js depends on a relative position of a HTML node. While first.js can change the position. It will not work.