jszap compressing javascript code
Download
Skip this Video
Download Presentation
JSZap : Compressing JavaScript Code

Loading in 2 Seconds...

play fullscreen
1 / 27

JSZap: Compressing JavaScript Code - PowerPoint PPT Presentation


  • 423 Views
  • Uploaded 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, …).

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

JSZap: Compressing JavaScript Code

Martin Burtscher, UT Austin

Ben Livshits & Ben Zorn, Microsoft Research

GauravSinha, IIT Kanpur

a web 2 0 application dissected
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
Lots of JavaScript being Transmitted

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

javascript on the wire
JavaScript on the Wire

JSZap

JavaScript

crunch

gzip

gzip -d

parser

AST

jszap approach
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
JSZap Compression

JavaScript

JSZap

gzip

jszap compression9
JSZap Compression

productions

1

JavaScript

identifiers

gzip

2

literals

3

talk outline
Talk Outline

productions

1

evaluation on real code

identifiers

2

literals

3

background asts
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

Literal Stream

  • 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
Benchmarking JSZap
  • JavaScript files up to 22K LOC
  • Variety of app types
  • Both hand-generated, and machine-generated
  • gzippedeverything
components of javascript source
Components of JavaScript Source
  • None of the categories can be ignored
  • Identifiers become more prominent with code growth
compressing the production stream
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
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
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
Compressing Literals
  • Symbol tables
  • Grouping literals by type
  • Pre-fixes and post-fixes
  • These techniques result in 5-10% savings compared to gzip
summary and conclusions
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
Questions?
  • Security (AdSafe)
  • Well-formedness
  • ASTrepresentation
  • Unblocking HTML parser
  • ?
  • Compression with JSZap
  • Caching and incremental updates
ad