-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Description
Do you want to request a feature or report a bug?
I want to report a performance bug.
What is the current behavior?
In projects with a lot of chunks, a lot of time is spent on RemoveParentModulesPlugin
.
The original report (angular/angular-cli#5618 (comment)) detailed a 1h build time for a non-production (no uglify etc) build.
The project uses Angular CLI and contains around ~2700 source files. This project has 376 chunks.
A similar sized project (https://github.com/filipesilva/angular-cli-test-repo) takes only a few minutes to build using the same options.
If the current behavior is a bug, please provide the steps to reproduce.
The project is closed source so I do not have a source, but the owner is available for some remote debugging (angular/angular-cli#5618 (comment)).
He provided CPU profiles for the first ~10m with node 8.4.0 (here) and with node 9.3.0 (here).
Both profiles show the majority of time being spent in RemoveParentModulesPlugin
, specifically within the hasModule
function. Also see the "Other information" bit at the end for a comparison with Webpack 4.
What is the expected behavior?
RemoveParentModulesPlugin
is optimized to allow having a lot of chunks without a big performance hit.
Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
Node.js 8.4.0, Webpack 3.10.0. Unknown browser/OS.
Other information.
I've been looking at Webpack 4 and thought maybe it could help since there are a lot of performance improvements there. The plugin in question has suffered some changes:
- in
webpack@3.10.0
: https://github.com/webpack/webpack/blob/b545b519b2024e3f8be3041385bd326bf5d24449/lib/optimize/RemoveParentModulesPlugin.js - in
webpack@4.0.0-alpha.3
: https://github.com/webpack/webpack/blob/9334fd8547831ded7f11e05319616a72ea0b4698/lib/optimize/RemoveParentModulesPlugin.js
It looks like there's a fair bit of optimizations changes there. But I'm not sure if the bottleneck has changed.
There's two places where time is being spent on the CPU profile:
This function hasn't changed though so I don't think it would speed up in this case.
/cc @pleerock @TheLarkInn
Activity
ooflorent commentedon Jan 5, 2018
I have an idea to fix this but I need a repo where the build is moderately long (from 10s to 5min) because of this plugin. Could someone provide it?
filipesilva commentedon Jan 5, 2018
I don't have one, I'm sorry... Investigation on this was mostly from exchanges with @pleerock over at angular/angular-cli#5618 (he's the one that experiences the problem).
I'm guessing it's because of the chunk quantity but to be honest it might not be.
sokra commentedon Jan 5, 2018
Please try webpack 4. There is a 80% chance that this has been fixed.
pleerock commentedon Jan 5, 2018
@filipesilva is it possible to use angular cli with webpack 4? (maybe with night builds) then I can check it?
ooflorent commentedon Jan 5, 2018
I've opened a PR to attempt to fix this. Another maybe-solution could be to replace the
Queue
by aUniqueQueue
to avoid processing the same chunk multiple times.filipesilva commentedon Jan 5, 2018
@pleerock I have angular/angular-cli#8611 but it probably will break on stuff. If you want to try it you'll have to link it to your project like detailed in https://github.com/angular/angular-cli#development-hints-for-working-on-angular-cli.
This might be a bit involved though. Happy to get on that screenshare you mentioned to help you set it up. Might have to disable stuff that uses plugins that don't yet work with webpack 4 as well.
pleerock commentedon Jan 10, 2018
@filipesilva I have new reports with your branch and webpack 4. First 10+ minutes of
RemoveParentModulesPlugin
execution withoutmax_old_space_size
being set:webpack4_no_high_memory.cpuprofile.zip
First 10+ minutes of
RemoveParentModulesPlugin
execution withmax_old_space_size
being set:webpack4_high_memory.cpuprofile.zip
This part of code:
Takes lot of loops. I didn't measure time but it was running like 50000 times each iteration took around half second. I wasn't successful in finishing this operation at all since don't know when. But I guess since node.js updation from 8 to 9 (as was recommended me before). I'll try to finish this operation and share reports how log it takes on node 9 and then run again on node 8 and compare results.
Also Im open to communication via skype, hangouts or similar service, just let me know how and when.
filipesilva commentedon Jan 10, 2018
Great job on getting those CPU profiles @pleerock! I think the high memory CPU log is the most accurate one because the other will have a lot of time spent on GC, and that doesn't really help narrow down the problem.
It looks like the seal hook is running into a lot of error cases:

@sokra is this information useful for you? I can jump on a hangouts with @pleerock and try some more advanced debugging if you can give us some directions.
ooflorent commentedon Jan 10, 2018
@pleerock @filipesilva have you tried the fix in my PR?
filipesilva commentedon Jan 10, 2018
I have not, no. I don't have access to the repo where the problem manifests. @pleerock can you try manually patching your local
webpack
node_modules with https://github.com/webpack/webpack/pull/6249/files?pleerock commentedon Jan 10, 2018
@filipesilva I will. btw it was running since I posted my message (over 3hrs) and Im going to stop execution since I don't see the end (last time I run it with webpack3 and node9 was over 6hrs and I stopped execution as well)
pleerock commentedon Jan 10, 2018
So, its same with provided code. Problem is still in
while
cycle. In 10+ minutes it run 2500 cycles each iteration took 200ms in average. Profile results:webpack4_extra_changes.cpuprofile.zip
pleerock commentedon Jan 10, 2018
Okay, I downgraded node from 9.3.0 to 8.9.4 and same
while
cycle iteration now takes ~50ms. As I previously told I wasn't able to finishserve
process at all since I upgraded to node 9.Results of running 10 minutes with node8:
webpack4_node8.cpuprofile.zip
44 remaining items