Presentation is loading. Please wait.

Presentation is loading. Please wait.

JSZap: Compressing JavaScript Code Martin Burtscher, UT Austin Ben Livshits & Ben Zorn, Microsoft Research Gaurav Sinha, IIT Kanpur.

Similar presentations


Presentation on theme: "JSZap: Compressing JavaScript Code Martin Burtscher, UT Austin Ben Livshits & Ben Zorn, Microsoft Research Gaurav Sinha, IIT Kanpur."— Presentation transcript:

1 JSZap: Compressing JavaScript Code Martin Burtscher, UT Austin Ben Livshits & Ben Zorn, Microsoft Research Gaurav Sinha, IIT Kanpur

2 A Web 2.0 Application Dissected 70,000+ lines of JavaScript code downloaded 2,855 Functions 1+ MB code Talks to 14 backend services (traffic, images, directions, ads, …) Talks to 14 backend services (traffic, images, directions, ads, …) 2

3 Lots of JavaScript being Transmitted 3 Up to 85% of a Web 2.0 app is JavaScript code!

4 AJAX: Tension Headaches 4 Execution can’t start without the code Move code to client for responsiveness

5 JavaScript on the Wire JavaScript crunch gzip -d parser AST JSZap gzip 5

6 JSZap Approach Represent JavaScript as AST instead of source Serialize the compressed AST Decompress directly into AST on client Use gzip as 2 nd -level (de-)compressor 6

7 Benefits of AST-based Compression Compression: less to transmit ASTs are blasted directly into the browser Reduced Latency Reduces mobile charges Reduces operator network costs: better for servers Reduced Network Bandwidth Ensures well-formedness of code Can use to check language subsets easily (AdSafe) Caching incremental updates Unblocking HTML parser Correctness, Security, and other Benefits 7

8 JSZap Compression JavaScript JSZap gzip 8

9 JSZap Compression JavaScript identifiers gzip literals productions 1 2 3 9

10 10 GZIP is a formidable opponent

11 JSZap vs. GZIP 11

12 Talk Outline 1 2 3 evaluation on real code 12

13 Background: ASTs a * b + c 1) E  E + T 2) E  T 3) T  T * F 4) T  F 5) F  id + * a b c 5 5 1 3 5 13 Expression Grammar Tree

14 A Simple Javascript Example var y = 2; function foo () { var x = "jscrunch"; var z = 3; z = y + y; } x = "jszap"; Identifier Stream y foo x z z y y x Literal Stream "jscrunch" 2 3 "jszap" 14 Production Stream 134...134...

15 Benchmarking JSZap Benchmark nameSource lines Source bytes gmonkey92217,382 getDOMHash1,13625,467 bing13,75877,891 bingmap13,47380,066 livemsg15,30793,982 bingmap29,726113,393 facebook15,886141,469 livemsg27,139156,282 officelive122,016668,051 JavaScript files up to 22K LOC Variety of app types Both hand- generated, and machine-generated gzipped everything 15

16 Components of JavaScript Source 16 None of the categories can be ignored Identifiers become more prominent with code growth None of the categories can be ignored Identifiers become more prominent with code growth

17 Compressing the Production Stream Frequency-based production renaming Differential encoding: 26 and 57 => 2 and 3 Chain rule: eliminate predictable productions Tree-based prediction-by-partial-match 17

18 PPMC Consider compressing – if (P) then X else X Should be very compressible if (P) then...abc... else...abc... 18 Tree context used to build a predictor Provides the next likely child node given context C and child position p Arithmetic coding: more likely=shorter IDs See paper for details

19 Production Compression with PPMC 19

20 Compressing the Identifier Stream Symbol tables instead of identifier stream: – Compress redundancy: offset into table – Global or local symbol tables – Use variable-length encoding Other techniques: – Sort symbols by frequency – Rename local variables 20

21 Variable-length Encoding for Identifiers is global? is renamed local 00… 01… fits in 1 byte? 11… 10… 21

22 Variable-Length Identifier Encoding 22

23 Symbol Tables: Effectiveness 23

24 Compressing Literals Symbol tables Grouping literals by type Pre-fixes and post-fixes These techniques result in 5-10% savings compared to gzip 24

25 Average JSZap Compression: 10% 25

26 Summary and Conclusions JSZap: AST-based compression for JavaScript Propose a range of techniques for compressing –Productions –Identifiers –Literals Preliminary results are encouraging: 10% savings over gzip Future focus – Latency measurements – Browser integration 26

27 Well- formedness Security (AdSafe) AST representation Unblocking HTML parser Caching and incremental updates Compression with JSZap 27 ? ? Questions?

28 References [1]Exploring Last n value Prediction – Martin Burtscher and Benjamin G. Zorn. [2]The Gzip Algorithm - http://www.gzip.org/algorithm.txthttp://www.gzip.org/algorithm.txt [3]FPC: A High-Speed Compressor for Double-Precision Floating-Point Data – Martin Burtscher and Paruj Ratanaworabhan. 28


Download ppt "JSZap: Compressing JavaScript Code Martin Burtscher, UT Austin Ben Livshits & Ben Zorn, Microsoft Research Gaurav Sinha, IIT Kanpur."

Similar presentations


Ads by Google