• Stars
    star
    1,343
  • Rank 34,982 (Top 0.7 %)
  • Language
    JavaScript
  • Created almost 9 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Investigating the overhead cost of compiled es2015

The cost of transpiling es2015 in 2016

tl;dr

There are a lot of tools to compile es2015 to es5. When choosing your compile stack you should be aware that tools that perform tree shaking and topological sorts of your code dependencies will result in smaller code bundles and faster js execution times.


The boom of es2015

With the recent es2015 boom 2016 javascript developers have a myriad of combinatorial choices when it comes to writing es2015 and compiling that code to es5 or lower. From closure compiler to browserify to uglify to webpack it is hard to know what is the best for compiling es2015 to run in browsers today.

Recently Malte Ubl pointed out a dramatic overall file size savings that the AMP team got when they switched from babel + browserify to closure compiler.

screen shot 2016-02-01 at 4 56 07 pm

Malte's post got me thinking about how each of the tools available to developers have a slightly different approach when it comes to dealing with import statements and combining multiple files together. The following analysis aims to look at the cost across multiple tools when the goal is to deliver a single JS blob down to the user when writing vanilla non-annotated es2015.

A simple test case:

To start with Let's take a look at this simple bit of code:

screen shot 2016-02-01 at 8 58 29 pm

Above is vanilla es2015 code -- To run this code in a browser however we first have to convert it to es5 using one of several options. Initially let's try babel + browserify, closure compiler, and rollup, and then compare the output.


Compiling this example with babel + browserify results in the following bundle:

screen shot 2016-02-01 at 8 59 23 pm

Now compare that result to using closure compiler: (using no optimization flags)

screen shot 2016-02-01 at 8 57 36 pm

Finally looking at rollup:

screen shot 2016-02-01 at 9 11 59 pm

rollup simply dead code eliminates everything :)

As you can see, you are paying a fairly high cost per module when using a tool like browserify, as compared to closure or rollup -- This simply put, boils down to overhead per module which increases the overall size of your bundle.


A slightly less trivial test:

For the next step in our analysis I will be using the vanilla es6 TodoMVC example from here https://github.com/tastejs/todomvc/tree/master/examples/vanilla-es6, For each of the tools that I measured against, I compiled the source code, and then verified that the app was working before taking any measurements.

The overhead and cost for this analysis was measured against the following metrics
  • File bundle size
  • Gzip size
  • Tool run time (gathered by time make <tool>)
  • *js execution time on page load (gathered by big-rig)
  • *js compile time (gathered by big-rig)

As a side note, the numbers that I gathered from the compile time metric and execution time were all within the margin of error of one another. so I will not be using those numbers to draw a hypothesis -- but the results are included at the end of the post.

Summary of findings:

Ignoring the outlier of traceur, people should heavily consider using a tool that does tree shaking (removal of unused code) and topological sorting of dependencies (ordering the dependencies so that you do not have to worry about import wrapping code). The difference between the final output size between a tool like browserify and rollup can well over 20%, even for a trivial app like TodoMVC.

image


Raw data
Tools File Size (bytes) gzip size (bytes) brotli size (bytes) js execution time (ms) js compile time (ms) tool run time (s)
closure 7847 2890 2529 53.15 9.56 7.938
[email protected] (babel + rollup + uglify) 11049 3393 2935 55.46 8.05 2.978
typescript + webpack 11128 3245 2827 56.57 8.45 4.636
babel + rollup + uglify 11423 3440 2989 50.81 7.26 2.396
typescript + browserify + uglify 11442 3415 2976 48.49 8.61 2.724
rollup-plugin-babel + uglify 11444 3447 2997 49.50 7.85 2.806
webpack@2 + babel + uglify 13346 3632 3157 51.28 8.35 2.007
webpack + babel + uglify 14130 3796 3307 51.28 9.59 2.045
babel + browserify + uglify 14409 3915 3422 53.37 8.85 4.947
babelify + uglify 14409 3915 3422 43.96 8.25 3.697
traceur + browserify + uglify 68699 18000 15945 66.60 7.95 3.085

Contributing / Running locally

Building Samples

make <babel | closure | typescript | rollup | traceur | ...>

Generating sizes
  • make <example-name>
  • make size
  • open demo in chrome... save timeline trace
  • npm i -g bigrig
  • bigrig <path-to-trace> --pp
View Demo

cd src && python -m SimpleHTTPServer

visit localhost:8000/

More Repositories

1

bundle-buddy

A tool to understand your bundle size and why files are in your bundle
TypeScript
2,891
star
2

drool

Automated memory leak detection and analysis
JavaScript
1,482
star
3

coverage-ext

Generate code coverage for any webpage
JavaScript
424
star
4

fidgetspin.xyz

TypeScript
298
star
5

noise

🔈 Recreating the dialup modem in JS
JavaScript
148
star
6

scrollin

📜 A leak free performance focused scroll util
JavaScript
122
star
7

thermal_print

webusb esc/pos thermal printer driver
TypeScript
102
star
8

issue-and-pr-templates

✨ Issue and PR templates! ✨
85
star
9

moji-brush

https://www.mojibrush.co
JavaScript
67
star
10

marionette-behaviors

a collection of useful marionette behaviors
CoffeeScript
64
star
11

webcomponent-bundle-analyzer

Analyze where your web component bundle bloat is coming from!
JavaScript
59
star
12

ivy

JavaScript
58
star
13

paper-typeahead

A typeahead polymer element, using material design
JavaScript
41
star
14

promise-semaphore

promise semaphore
JavaScript
30
star
15

edit.sx-frontend

the front end app for edit.sx
CSS
30
star
16

headless-snap

JavaScript
24
star
17

polymer-marionette

Marionette and Polymer meet!
CSS
22
star
18

dogesay

http://dogesay.com/wow
CoffeeScript
22
star
19

engine-deps

install dependencies based on node version
JavaScript
20
star
20

css-diff

diff your Css Stylus and Scss
JavaScript
20
star
21

monocle

a tool for watching things
JavaScript
17
star
22

365

sketch a day
JavaScript
14
star
23

pieChart

pieChart
JavaScript
12
star
24

travis-sauce-connect

A pattern repo for running sauce-connect on travis.ci
JavaScript
10
star
25

lcdsysinfo

lcdsysinfo web usb driver
TypeScript
10
star
26

marionette-browserify

sample project for how to use backbone.marionette within the ever popular browserify
JavaScript
9
star
27

tiny-games

JavaScript
7
star
28

light-paint

CoffeeScript
7
star
29

marionette-2.4-demos

JavaScript
7
star
30

testing-h2-push

HTML
7
star
31

infestor

Inject content into your server responses
JavaScript
7
star
32

angular-samples

angular fundamentals
JavaScript
6
star
33

streaming-css

HTML
6
star
34

wavesvg

wavesvg
CoffeeScript
6
star
35

grifter

TypeScript
5
star
36

twinkie

A polymer(1)&&(2) template parser + interface printer
TypeScript
5
star
37

hub-bot

automate OSS review churn
JavaScript
4
star
38

dr_mojo

JavaScript
4
star
39

White-Board

a socket.io html5 white board for real time collaboration
JavaScript
4
star
40

perf.html

JavaScript
4
star
41

weathers

node.js weather wrapper
JavaScript
4
star
42

house-hunt-api

CoffeeScript
4
star
43

strands

4
star
44

polymer-drool

JavaScript
3
star
45

pollster

TypeScript
3
star
46

CircleUI

babies cry when they use this
JavaScript
3
star
47

digital-doodles

digital doodles
CoffeeScript
3
star
48

rap-air-horn

android rap airhorn
Java
3
star
49

magnets

realtime fridge magnets
JavaScript
3
star
50

yaml-validate

get validating
JavaScript
3
star
51

webkit-remote-debugger-translator

JavaScript
3
star
52

psd.js

Mirror of Meltingice's CoffeeScript PDF parser library.
CoffeeScript
3
star
53

chroma

chroma key in html5
JavaScript
2
star
54

jsconf-2015-stream

jsconf-2015-stream
JavaScript
2
star
55

Docker-Firefox-node.js-webdriver-base

Shell
2
star
56

node_demo

JavaScript
2
star
57

multi-select-order

multiple select ordering
2
star
58

pebble-run

C
2
star
59

goat-swipe

like tinder but for goats
Objective-C
2
star
60

psdgrade

psdgrade
JavaScript
2
star
61

jquery.metal

more metal for your site
JavaScript
2
star
62

clojure-snake

a snake clone written in clojure
Clojure
2
star
63

trace

TypeScript
2
star
64

Blog-Posts

1
star
65

baudot-code-to-string

JavaScript
1
star
66

ios-trashcan

Objective-C
1
star
67

fieri_compress

HTML
1
star
68

roots-asset-expand

CoffeeScript
1
star
69

char-to-baudot

char to Baudot-Murray code lookup
JavaScript
1
star
70

SE-menu-toggle

make the menus on your SE site toggle
JavaScript
1
star
71

home-hunt

CSS
1
star
72

SE_menuFade

JavaScript
1
star
73

me

HTML
1
star
74

argumentParser

JavaScript
1
star
75

shootit

JavaScript
1
star
76

browserify-global-lookup-shim

JavaScript
1
star
77

samsaccone.com

samsaccone.com
1
star
78

lazer-space-goat

TypeScript
1
star
79

string-to-baudot-code

JavaScript
1
star
80

billTracker

Ruby
1
star
81

ansi-stream

an ansi to html parser
JavaScript
1
star
82

TID_workshop_2013

CoffeeScript
1
star
83

transit

A realtime feed of all the buses in Boston
JavaScript
1
star
84

behave-ui-hotkeys

A hotkeys Marionette Behavior
JavaScript
1
star
85

dogestyle

1
star
86

marionette-testing

JavaScript
1
star
87

timeline-grid

JavaScript
1
star
88

string-to-binary

JavaScript
1
star
89

pixl

http://pixl.jit.su/
CoffeeScript
1
star
90

testing-the-dom

JavaScript
1
star
91

joey

HTML
1
star
92

sveltekit-388

Svelte
1
star
93

unwrap

unwrap UMD
JavaScript
1
star
94

rtc-sample

rtc-sample
JavaScript
1
star
95

fried-twinkie

TypeScript
1
star
96

phpPhoto

A Databaseless Photo Website Template
PHP
1
star
97

sno-country

snocountry node api wrapper
JavaScript
1
star
98

wordpress-to-tumblr

nodejs wordpress-to-tumblr importer
CoffeeScript
1
star
99

home-energy-score-api

API interface for the HES SOAP based API.
CoffeeScript
1
star
100

engine-fail

JavaScript
1
star