webpack icon indicating copy to clipboard operation
webpack copied to clipboard

Finish Modules steps tooks long time

Open JiangWeixian opened this issue 1 year ago • 2 comments

Currently, I develop a huge react project with

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:

image

image

Any ideas to optimize it? I already tried:

  1. https://github.com/webpack/webpack/issues/8557 replace dynamic import to promise.resolve
  2. 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 avatar Oct 17 '23 05:10 JiangWeixian

@JiangWeixian Maybe you have a lot of modules... We need more information to help you...

alexander-akait avatar Dec 20 '23 18:12 alexander-akait

@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.

  1. only compile used route
  2. 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
  3. 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

JiangWeixian avatar Dec 22 '23 03:12 JiangWeixian

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.

webpack-bot avatar Mar 23 '24 07:03 webpack-bot