Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Slow for webpack-dev-server when recompile #3311

Open
2 tasks
fengerzh opened this issue Aug 18, 2021 · 7 comments
Open
2 tasks

[Feature] Slow for webpack-dev-server when recompile #3311

fengerzh opened this issue Aug 18, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@fengerzh
Copy link

fengerzh commented Aug 18, 2021

  • I'd be willing to implement this feature (contributing guide)
  • This feature is important to have in this repository; a contrib plugin wouldn't do

Describe the user story

For pnp mode, everything works fine, but when running React project with yarn start, a webpack-dev-server running, if change even one line of code, it will begin to compile again, and it will take about 30 seconds to finish. If I switch to node_modules mode, it only take about 1 second.

Describe the solution you'd like

I read issues with yarn run performance of #1817 and #973, both seems not similiar to my issue. In my situation, yarn run start speed is acceptable, it will take about 30 seconds even with node-modules mode. The problem is for recompiling, even change one line of code, webpack-dev-server will begin to recompile, this will take about 1 second in node-modules mode, but will take 30 seconds in pnp mode, I hope to know why the difference is so big, what exactly causing the problem.

Describe the drawbacks of your solution

Seems I have no solution yet.

Describe alternatives you've considered

Seems no alternatives, the only solution is not only optimize the yarn run performance, but also consider recompiling performance when webpack-dev-server running.

@fengerzh fengerzh added the enhancement New feature or request label Aug 18, 2021
@noahnu
Copy link
Contributor

noahnu commented Aug 18, 2021

Webpack treats each "virtual" as its own module, so a project with a lot of PNP virtuals will be slower than a node_modules project with no virtuals. I have a webpack feature request here: webpack/webpack#13813

@larixer
Copy link
Member

larixer commented Aug 18, 2021

@noahnu node_modules has virtuals too, they take the form of duplicate copies of the same version of the package inside node_modules, not all copies are due to peer dependencies, but some of them - for sure. What is the difference in Webpack bundle size between pnp and nm, do you have repro to look at?

@fengerzh
Copy link
Author

@larixer For my project, the bundle size are almost same, there is no big difference from pnp and nm.

@larixer
Copy link
Member

larixer commented Aug 18, 2021

@fengerzh It means the problem inside webpack is related to non-optimal pnp tree traversal and not related to virtuals at all.

@larixer
Copy link
Member

larixer commented Aug 18, 2021

@noahnu I think you should open different issue, because @fengerzh have no problems with bundle size, it means your issue is different.

@arcanis
Copy link
Member

arcanis commented Aug 18, 2021

Might also be related to webpack/webpack#12483 (comment)?

@fengerzh
Copy link
Author

I found there are lots of require at the head of webpackDevServer.config.js and webpack.config.js like this:

const fs = require('fs');
const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
const evalSourceMapMiddleware = require('react-dev-utils/evalSourceMapMiddleware');
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
const ignoredFiles = require('react-dev-utils/ignoredFiles');
const redirectServedPath = require('react-dev-utils/redirectServedPathMiddleware');
const paths = require('./paths');
const getHttpsConfig = require('./getHttpsConfig');

Do I need to wrap these require as this?

const {createRequire} = require(`module`);

// We'll be able to inspect the dependencies of the module passed as first argument
const targetModule = process.argv[2];

const targetRequire = createRequire(targetModule);

const resolved = targetRequire.resolve(`eslint`);
const instance = targetRequire(resolved); // <-- still important

@fengerzh fengerzh changed the title [Feature] Slow for webpack-dev-server hot reload [Feature] Slow for webpack-dev-server when recompile Aug 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants