/salestrader [ct5-post-conversion|✔] 14:27 $ npm start
Version: webpack 2.3.3
Time: 57358ms
webpack: Compiled successfully.
/salestrader [ct5-post-conversion|✔] 14:28 $ npm start
Time: 16931ms
webpack: Compiled successfully.
Given
"/Users/briand/dev/salestrader/apps/salestrader/src/index.js"
Webpack is a single core application.
What happens if we parallelise the parsing, extracting and resolving of dependencies?
// PARENT PROCESS.
const { fork } = require("child_process"); // 1
const childPath = join(__dirname, "../child/child-process-module");
const childProcess = fork(childPath); // 2
childProcess.on("message", (message) => handleChildProcessMessage(message)); // 3
// CHILD PROCESS.
process.on("message", handleParentMessage); // 3
process.send(message); // 3
Salestrader: 1006 files.
1 core: 2.6s
2 core: 1.7s
about 30-35% speed up
Windows
1 core: 12s
2 core: 7.5s
4 core: 6s
1 core: 19s
2 core: 12.5s
Multi process support could speed up Webpack builds by 30%+ and it does seem to scale with the # of physical cores.
Spike adding it to Webpack/creating loader/plugin?
https://github.com/webpack/webpack/issues/914
Another way to improve performance is to cache work (transforms).
https://github.com/mzgoddard/hard-source-webpack-plugin
With this applied sales trader goes from 17s to 11.5s on second build.
There is a plugin that allows parallel loader execution
https://github.com/webpack/webpack/issues/1810
https://github.com/amireh/happypack
Using it on babel-loader
First build: 18s!
Subsequent: 11.5s...
Multi-process can help.
Caching helps.
Babel is a slow blob monster.
There is nothing new under the sun.
https://github.com/webpack/webpack/issues/1810
https://github.com/webpack/webpack/issues/250
https://github.com/webpack/webpack/issues/1905