webpack
webpack copied to clipboard
Finish Modules steps tooks long time
Currently, I develop a huge react
project with
-
[email protected]
. - Apple M1 Max
When edit some files to trigger HMR, in progress plugin output, finishModules
step tooks long time. So I add https://github.com/jantimon/cpuprofile-webpack-plugin to find out which step cost a lot, here is cpu profile screenshot:
Any ideas to optimize it? I already tried:
- https://github.com/webpack/webpack/issues/8557 replace dynamic
import
topromise.resolve
- disable cache and progress in dev mode
It does't help. But when I comments sortItemsWithChunkIds
inside Compliation.js
, e.g.
// this.sortItemsWithChunkIds();
It make finish module step from 7s
to 2s
.
Originally posted by @JiangWeixian in https://github.com/webpack/webpack/discussions/17751
@JiangWeixian Maybe you have a lot of modules... We need more information to help you...
@alexander-akait yep..
It's a huge project, server and client compiler will each compile 25k+ modules. I took some methods (from next.js
and other repos) to optimize it.
- only compile used route
- shake unused modules earlier(in swc transfrom stage), e.g. remove
no_ssr
&useEffect & useLayoutEffect
code in server compiler; use swc optimizier & minify options in swc-loader - optimize barrel packages
After above methods, server and client compiler will each compile 10k modules...(in MAC M1 Pro, from 240s startup to 110s) It looks like no more methods to make it less :(.
I will try rspack
to make compile fast in next few months
This issue had no activity for at least three months.
It's subject to automatic issue closing if there is no activity in the next 15 days.