Slide 1

Slide 1 text

Webpackのビルド時間を  1/3にした話  2017/10/06 Gotanda.js #9 @mizuki_r

Slide 2

Slide 2 text

@mizuki_r • シニアフロントエンドエンジニア • エンジニア 2 #javascript #gotandajs #meguroes #perl #kichijojipm 五反田のM社で位置ゲー開発に携わる。
 スクラム教に入信したって噂。DDDを ようやく真面目に学び始めた about me こんな人です

Slide 3

Slide 3 text

本題の前にちょっと プロモーション

Slide 4

Slide 4 text

Syntagme.js v1.0.0 リリースしました ٩(๑´3`๑)۶  https://github.com/rymizuki/syntagmejs/releases/tag/v1.0.0

Slide 5

Slide 5 text

本題 

Slide 6

Slide 6 text

Webpackのビルド時間を  1/3にした話 

Slide 7

Slide 7 text

 …基本的な話です 

Slide 8

Slide 8 text

結論

Slide 9

Slide 9 text

結論 • thread-loader • cache-loader

Slide 10

Slide 10 text

はい

Slide 11

Slide 11 text

ことの背景

Slide 12

Slide 12 text

ある巨大リポジトリ

Slide 13

Slide 13 text

巨大… • JavaScript • 781ϑΝΠϧɺ25934ߦɺ808610จࣈ • CoffeeScript • 336ϑΝΠϧɺ10266ߦɺ338988จࣈ • SCSS • 361ϑΝΠϧɺ43304ߦɺ1088861จࣈ • and moreʂ

Slide 14

Slide 14 text

ビルド時間 Execution Time (2017-10-05 00:12:15 UTC) webpack 2m 10.7s Total 2m 11.9s

Slide 15

Slide 15 text

もっと早くしたい…

Slide 16

Slide 16 text

Buld Performance https://webpack.js.org/guides/build-performance/

Slide 17

Slide 17 text

最新の安定版を使え Use the latest webpack version. We are always making performance improvements. The latest stable version of webpack is:

Slide 18

Slide 18 text

必要最低限のモジュールをロー ドする Apply loaders to the minimal number of modules necessary.

Slide 19

Slide 19 text

小さい少数のモジュールを使 え Each additional loader/plugin has a bootup time. Try to use as few different tools as possible.

Slide 20

Slide 20 text

resolveは最小限に • resolve.extensions • resolve.modules • resolve.mainFiles • resolve.descriptionFiles • etc….

Slide 21

Slide 21 text

DLLPlugin使え Use the DllPlugin to move code that is changed less often into a separate compilation. This will improve the application's compilation speed, although it does increase complexitity of the build process.

Slide 22

Slide 22 text

Smaller = Faster Decrease the total size of the compilation to ncrease build performance. Try to keep chunks small.

Slide 23

Slide 23 text

thread-loader使え The thread-loader can be used to offload expensive loaders to a worker pool.

Slide 24

Slide 24 text

cache-loader使え Enable persistent caching with the cache-loader. Clear cache directory on "postinstall" in package.json.

Slide 25

Slide 25 text

node-sassは遅いぞ node-sass has a bug which blocks threads from the Node.js threadpool. When using it with the thread- loader set workerParallelJobs: 2.

Slide 26

Slide 26 text

そもそも

Slide 27

Slide 27 text

3年の重み • grunt-contrib-coffeeͰconcat͢Δ࣌୅ͷίʔυ͕·ͩେྔʹ͋Δ • webpack΁ͷίʔυҠ؅ͷ్த • coffeeͱes2015ͷؒͷࢠ • ๲େͳscss…. • angular 1.x ….. • ྺ࢙͕ॏ͍

Slide 28

Slide 28 text

それでもなんとかできないか?

Slide 29

Slide 29 text

thread-loader

Slide 30

Slide 30 text

thread-loader • WorkerPoolΛ༻ҙͯ͠ɺͦͷதͰloaderͰ࣮ߦ͢ Δ • ෳ਺εϨουͰ࣮ߦͰ͖Δ • σϑΥϧτͰ20JobΛฒྻͰಈ͔͢ • node-sass͕ϒϩοΫͯ͠·͏໰୊ͷղܾࡦ

Slide 31

Slide 31 text

cache-loader

Slide 32

Slide 32 text

cache-loader • ϑΝΠϧͷmtimeͰΩϟογϡ͠ͱ͘

Slide 33

Slide 33 text

webpack.config.js

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

result

Slide 37

Slide 37 text

Execution Time (2017-10-05 00:37:56 UTC) webpack 1m 58.6s Total 1m 59.8s ✨ Done in 125.42s.

Slide 38

Slide 38 text

まあ、まだキャッシュ 乗ってないので….

Slide 39

Slide 39 text

Execution Time (2017-10-05 00:40:48 UTC) webpack 33.8s Total 35.3s ✨ Done in 40.71s.

Slide 40

Slide 40 text

だいたい1/3!!!

Slide 41

Slide 41 text

あれ…?

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

まとめ

Slide 44

Slide 44 text

まとめ • thread-loaderͰWorkerPoolͰॲཧ͢Δ͜ͱͰ ଟগͳΓͱ଎౓͕վળ͢Δ • cache-loader࢖͏͜ͱͰඞཁͳ෦෼͚ͩͷϏ ϧυͰࡁΉͷͰ࣌ؒͷ୹ॖʹͳΔ

Slide 45

Slide 45 text

node-sassは? • thread-loader͍ΕͨΒͳΜ͔ॲཧ͕ࢭ·Δ… • fast-sass-loaderͳΔ΋ͷ͕͋Δ • ͕ɺfunctions͕࣮૷͞Εͯͳ͔ͬͨ • cacheͰߴ͍վળ͕Ͱ͖ͨͷͰҰ୴ڐ༰

Slide 46

Slide 46 text

それでも 最大1/3 おためしあれ!

Slide 47

Slide 47 text

ご清聴 ありがとうございました