Slide 1

Slide 1 text

Manage the cost of JavaScript Paipo / Frontend Engineer @ Mercari

Slide 2

Slide 2 text

Outline ● How browser works ● What is the cost of JavaScript ● Performance Budget ● Experiment performance budget on my project

Slide 3

Slide 3 text

How browser works

Slide 4

Slide 4 text

Source: https://developers.google.com/web/updates/2018/09/inside-browser-part1

Slide 5

Slide 5 text

Source: https://developers.google.com/web/updates/2018/09/inside-browser-part3

Slide 6

Slide 6 text

Source: https://developers.google.com/web/updates/2018/09/inside-browser-part4

Slide 7

Slide 7 text

What does it mean by the cost of JavaScript?

Slide 8

Slide 8 text

Why do we blame Javascript so hard? Source: https://developers.google.com/web/fundamentals/performance/optimizing-javascript/tree-shaking/

Slide 9

Slide 9 text

Reasons ● Javascript is compressed ● More than loading Javascript ...

Slide 10

Slide 10 text

Types of costs ● Load through network ● Parse, compile and execute ● Memory cost

Slide 11

Slide 11 text

Time to Interactive “ The Time to Interactive (TTI) metric measures how long it takes a page to become interactive ” (Source)

Slide 12

Slide 12 text

Example: Strong network & CPU Example: Strong network & CPU

Slide 13

Slide 13 text

Profile result and summary graph (No throttling)

Slide 14

Slide 14 text

Example: Fast 3G with 4x slower CPU Example: Fast 3G with 4x slower CPU

Slide 15

Slide 15 text

Profiling result and summary graph (Throttling)

Slide 16

Slide 16 text

Performance Budget

Slide 17

Slide 17 text

Performance Budget ● Metric for things like Javascript bundle size and Time to Interactive ● Not a one time task ● Keep this budget in mind when making decisions

Slide 18

Slide 18 text

Experiment Performance Budget on my project

Slide 19

Slide 19 text

Initial Page

Slide 20

Slide 20 text

Webpack bundle analyzer

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Initial Loading size

Slide 23

Slide 23 text

Add bundle size dependency and testing scripts

Slide 24

Slide 24 text

Bundle size check in CI

Slide 25

Slide 25 text

Github PR Check

Slide 26

Slide 26 text

Improving Strategies ● Code splitting ● Tree shaking

Slide 27

Slide 27 text

Code Splitting

Slide 28

Slide 28 text

Code splitting (code change)

Slide 29

Slide 29 text

Code splitting (CI result)

Slide 30

Slide 30 text

Code splitting (github PR check)

Slide 31

Slide 31 text

Code splitting (chrome dev tool result)

Slide 32

Slide 32 text

Tree Shaking

Slide 33

Slide 33 text

Tree Shaking (test code coverage)

Slide 34

Slide 34 text

Tree Shaking (test code coverage)

Slide 35

Slide 35 text

Tree Shaking with ContextReplacementPlugin

Slide 36

Slide 36 text

Tree shaking (test code coverage again)

Slide 37

Slide 37 text

Tree shaking (CI result)

Slide 38

Slide 38 text

Tree shaking (github PR check)

Slide 39

Slide 39 text

Webpack bundle analyzer

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

Conclusion

Slide 42

Slide 42 text

Don’t block your main thread

Slide 43

Slide 43 text

Manage the cost of JavaScript Earlier

Slide 44

Slide 44 text

Design Develop Test Performance Tuning

Slide 45

Slide 45 text

Design Develop Test Performance Budget Check Design Develop Test Performance Budget Check Design Develop Test Performance Budget Check

Slide 46

Slide 46 text

Automate your Performance Budget check

Slide 47

Slide 47 text

Thank you!