Jszap compressing javascript code
Download
1 / 27

JSZap : Compressing JavaScript Code - PowerPoint PPT Presentation


  • 423 Views
  • Updated On :

JSZap : Compressing JavaScript Code. Martin Burtscher , UT Austin Ben Livshits & Ben Zorn, Microsoft Research Gaurav Sinha , IIT Kanpur. A Web 2.0 Application Dissected. 1+ MB code. Talks to 14 backend services (traffic, images, directions, ads, …).

Related searches for JSZap : Compressing JavaScript Code

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'JSZap : Compressing JavaScript Code' - elina


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Jszap compressing javascript code l.jpg

JSZap: Compressing JavaScript Code

Martin Burtscher, UT Austin

Ben Livshits & Ben Zorn, Microsoft Research

GauravSinha, IIT Kanpur


A web 2 0 application dissected l.jpg
A Web 2.0 Application Dissected

1+ MB code

Talks to 14 backend services

(traffic, images,

directions, ads, …)

70,000+ lines of JavaScript code downloaded

2,855 Functions


Lots of javascript being transmitted l.jpg
Lots of JavaScript being Transmitted

Up to 85% of a Web 2.0 app is JavaScript code!



Javascript on the wire l.jpg
JavaScript on the Wire

JSZap

JavaScript

crunch

gzip

gzip -d

parser

AST


Jszap approach l.jpg
JSZap Approach

  • Represent JavaScript as AST instead of source

  • Serialize the compressed AST

  • Decompress directly into AST on client

  • Use gzip as 2nd-level (de-)compressor



Jszap compression l.jpg
JSZap Compression

JavaScript

JSZap

gzip


Jszap compression9 l.jpg
JSZap Compression

productions

1

JavaScript

identifiers

gzip

2

literals

3


Gzip is a formidable opponent l.jpg
GZIP is a formidable opponent


Jszap vs gzip l.jpg
JSZap vs. GZIP


Talk outline l.jpg
Talk Outline

productions

1

evaluation on real code

identifiers

2

literals

3


Background asts l.jpg
Background: ASTs

Grammar

Expression

a * b + c

Tree

1

+

1) E  E + T

2) E  T

3) T T * F

4) T  F

5) F  id

3

*

c

5

a

b

5

5


A simple javascript example l.jpg

  • Production Stream

A Simple Javascript Example

vary = 2;

function foo () {

varx = "jscrunch";

varz = 3;

z = y + y;

}

x = "jszap";

1 3 4 ... 1 3 4 ...

y foo x z z y y x

"jscrunch" 2 3 "jszap"


Benchmarking jszap l.jpg
Benchmarking JSZap

  • JavaScript files up to 22K LOC

  • Variety of app types

  • Both hand-generated, and machine-generated

  • gzippedeverything


Components of javascript source l.jpg
Components of JavaScript Source

  • None of the categories can be ignored

  • Identifiers become more prominent with code growth


Compressing the production stream l.jpg
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


Slide18 l.jpg
PPMC

  • 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

  • Consider compressing

    • if (P) then X else X

  • Should be very compressible

    • if (P) then ...abc... else ...abc...

P

X

X



Compressing the identifier stream l.jpg
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





Compressing literals l.jpg
Compressing Literals

  • Symbol tables

  • Grouping literals by type

  • Pre-fixes and post-fixes

  • These techniques result in 5-10% savings compared to gzip


Average jszap compression 10 l.jpg
Average JSZap Compression: 10%


Summary and conclusions l.jpg
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


Questions l.jpg
Questions?

  • Security (AdSafe)

  • Well-formedness

  • ASTrepresentation

  • Unblocking HTML parser

  • ?

  • Compression with JSZap

  • Caching and incremental updates