Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Web Apps performance & JavaScript compilers
Search
Roman Liutikov
December 04, 2016
Programming
140
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Web Apps performance & JavaScript compilers
MostJS Frameworks Day @ Dec 4 2016
Roman Liutikov
December 04, 2016
More Decks by Roman Liutikov
See All by Roman Liutikov
ClojureScript × Type Inference
roman01la
0
49
React Kyiv – Dec 19, 2017
roman01la
1
230
React & ClojureScript in production at Attendify
roman01la
0
200
Introduction to React.js
roman01la
0
97
React Native: Native Mobile Development in JavaScript @ LvivJS 2016
roman01la
0
170
React Native: Are we there yet? (Pokémon edition) @ VinnytsiaJS '16
roman01la
0
430
React Native: Native mobile development with JavaScript
roman01la
0
210
ClojureScript, что ты такое?
roman01la
1
230
ClojureScript: what are you?
roman01la
2
140
Other Decks in Programming
See All in Programming
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
430
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
1
110
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
460
Simple Storage Service(S3) is not simple
iwatsukayura
0
120
AHC070解法紹介
eijirou
0
150
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
370
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
520
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
3.1k
カツオ、ご期待ください
suneo3476
0
130
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
320
setup-vp GitLab対応の裏側
naokihaba
0
140
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.2k
Featured
See All Featured
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
310
Darren the Foodie - Storyboard
khoart
PRO
4
4k
For a Future-Friendly Web
brad_frost
183
10k
How to Talk to Developers About Accessibility
jct
2
560
How to Think Like a Performance Engineer
csswizardry
28
2.8k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Mobile First: as difficult as doing things right
swwweet
225
10k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
960
My Coaching Mixtape
mlcsv
0
330
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
780
The Invisible Side of Design
smashingmag
301
52k
Transcript
Web Apps performance & JavaScript compilers Roman Liutikov Attendify
Web Apps nowadays 5 MB of awesome web technologies is
loading...
None
None
This is NOT good • Makes people wait • Eats
their traffic and money • Everyone hates you • You loose money
WTMHLM performance anti-pattern
the goal is to Reduce Time To Interaction
The right way _______ index.html route-1.js common-1.js I can see
it I can use it route-2.js Pre-caching Server Rendering (JS & CSS)
Code Splitting
Code splitting Divide JS bundle into chunks route-1.js route-2.js route-3.js
route-4.js ... common-1.js common-2.js Webpack CommonsChunkPlugin
Initial load Load initial route and its common chunk route-1.js
common-1.js
The compiler is to blame for everything
Smarter compiler means smaller output size & eval time
Compiler optimizations
Dead code elimination Remove code that can never be executed
const dec = (x) => x - 1; const inc = (x) => x + 1; const x = 0; const y = 1; inc(x); inc dec y x UglifyJS Rollup Babili Closure Compiler Dependency graph
Tree-shaking (A special case of DCE) Do not include unused
exports // math.js export const dec = (x) => x - 1; export const inc = (x) => x + 1; // main.js import { inc } from 'math'; const x = 0; const y = 1; inc(x); Webpack 2 Rollup Closure Compiler
Function call inlining Replace a function call with its body
const person = { fname: 'John', lname: 'Doe' }; function fullName(p) { return p.fname + ' ' + p.lname; } console.log(fullName(person)); Closure Compiler const person = { fname: 'John', lname: 'Doe' }; console.log( person.fname + ' ' + person.lname);
Property flattening (collapsing) Collapse object properties into separate variables const
person = { fname: 'John', lname: 'Doe' }; console.log( person.fname + ' ' + person.lname); Closure Compiler const person$fname = 'John'; const person$lname = 'Doe'; console.log( person$fname + ' ' + person$lname);
Constant folding Evaluate constant expressions at compile time UglifyJS Babili
Closure Compiler const person$fname = 'John'; const person$lname = 'Doe'; console.log('John Doe'); const person$fname = 'John'; const person$lname = 'Doe'; console.log( person$fname + ' ' + person$lname);
Known methods folding Evaluate known methods at compile time Closure
Compiler '012345' 'World!' 99 [0, 1, 2, 3, 4, 5].join(''); 'Hello, world!'.substr(7, 11); parseInt('99 UAH');
Code splitting in Webpack Module level splitting a b c
d a b c a b a c input output
Code splitting in Closure Compiler Function/method & variable level splitting
a b c d a a b a c input output b c
Precache & Lazy load
Precache route-1.js common-1.js Load and/or cache chunks in background UI
is ready Load in bg
Lazy load route-1.js common-1.js Load chunks on demand Navigation Load
chunk route-2.js ...
Code splitting & Lazy loading in Webpack 2 Per route
chunks with React Router <Route path="user/:id" getComponent={(loc, cb) => { System.import("pages/User") .then((module) => cb(null, module)); }}>
Preload chunks * Chrome, Opera & Chrome for Android <head>
<link rel="preload" as="script" href="chunk-1.js"> <link rel="preload" as="script" href="chunk-2.js"> ... </head>
Precache with Service Worker (sw-precache) Preload + Offline support plugins:
[ new SWPrecacheWebpackPlugin({ cacheId: "app", filename: "app-sw.js", staticFileGlobs: [ "app/js/**.js" ] })]
What about framework size?
Ahead-of-time compilation Reduce runtime overhead Templates AOT compilation in Angular
2 & Vue.js 2
None
Preact Vue.js Riot.js Lightweight alternatives
Out of the box code splitting is coming to
Should I use code splitting? Yes
Should I use server-side rendering? Maybe
Should I care about compiler? NO
@roman01la Thank You!