Repository navigation
Description
Command
serve
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
12.2.17
Description
I recently tried to upgrade our large enterprise application (~1300 components) from Angular v12 to v15. After the upgrade, I noticed that 'ng serve' incremental build times had increased from around (15s - 25s) on Angular v12 to (115s - 130s) on Angular v15. This kind of degradation in build performance was not expected. Here are my settings in the angular.json file for our 'development' config.
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true,
"aot": false,
"progress": true
}
I tried a number of thing to see if I could bring down the time. One that gave a limited improvement was to move the entries from the "scripts" section in the angular.json file and directly reference them in the index.html file via script tags instead. This reduced the incremental build times to (95s - 100s)
Minimal Reproduction
I wasn't able to reproduce issue in a smaller application and I can't share our code base.
Exception or Error
No response
Your Environment
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 15.0.4
Node: 14.21.2
Package Manager: npm 6.14.17
OS: win32 x64
Angular: 15.0.4
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1500.4
@angular-devkit/build-angular 15.0.4
@angular-devkit/core 15.0.4
@angular-devkit/schematics 15.0.4
@angular/cdk 15.0.3
@angular/flex-layout 14.0.0-beta.41
@angular/material 15.0.3
@schematics/angular 15.0.4
rxjs 6.6.0
typescript 4.8.4
Anything else relevant?
No response
Activity
alan-agius4 commentedon Jan 31, 2023
Can you please share the entire
buildandservesections of yourangular.jsonand the exact command that you are executing?fearghalom commentedon Jan 31, 2023
The command: node --max-old-space-size=16384 ./node_modules/@angular/cli/bin/ng serve
alan-agius4 commentedon Feb 1, 2023
@fearghalom, you are using a 3rd party builder that is not supported by the Angular team. Can you try to see if the problem persists if you use the supported builder?
fearghalom commentedon Feb 1, 2023
I was using the custom 3rd party builder for the production build but still using "@angular-devkit/build-angular:dev-server" for the dev build (ng serve).
I updated the angular.json anyway to remove the usage of the custom builder but it made no impact to the build times.
alan-agius4 commentedon Feb 2, 2023
Hi @fearghalom, in that case we'd require an CPU profile to investigate this any further.
fearghalom commentedon Feb 2, 2023
Hi Alan, do you have instructions on how to do that?
alan-agius4 commentedon Feb 2, 2023
See: https://github.com/angular/angular-cli/blob/main/docs/DEVELOPER.md#cpu-profiling
fearghalom commentedon Feb 2, 2023
cpuprofile.zip
alan-agius4 commentedon Feb 3, 2023
@fearghalom, are these profile for a build? I am not seeing much happening in these. Mostly it's just the process being idle.
fearghalom commentedon Feb 3, 2023
These cpu profile logs were recorded for 'ng serve':
node --cpu-prof --max-old-space-size=16384 ./node_modules/@angular/cli/bin/ng serve
I noticed that there were 5 .cpuprofile files produced during the initial build but nothing was logged after that.
alan-agius4 commentedon Feb 3, 2023
Since you are profiling a rebuild in this case it would probably better to profile manually using the steps mentioned in #8259 (comment)
fearghalom commentedon Feb 3, 2023
Here's the profile for the rebuild:
rebuild_profile_CPU-20230203T225405.zip
alan-agius4 commentedon Feb 8, 2023
Thanks for the profile.
I did take a look at it and I can see is that there are a lot of IO operations specifically
readlinkSyncwith aggregated total time of57.79s.See screenshots below;


Also, I recommend is to update to Node.js 16, remove
--max-old-space-size=16384which should not be needed with Node.js 16 and see if the problem is still reproducible.That said, I highly doubt that this is something that we can action from our end.
fearghalom commentedon Feb 8, 2023
Thanks Alan for taking a look. I had actually upgraded to Node v18.10.0 to perform the profiling as it was crashing when I tried to use v14.21.2. I gave Node v16 a go also but it didn't make any difference to the rebuild times.
Can anything further be done on this? We probably can't move to v15 with these rebuild times. As I mentioned previously, I tried with angular 14 and the rebuild times were also slow but Angular 13 was comparable to Angular 12.
One thing I did notice that brought down the rebuild time, was to remove the entries from the "scripts" section in the angular.json file and reference them directly in the index.html file. Doing this, knocked about 30 seconds off the rebuild time.
I profiled it and it seems that having even one item in the scripts section of the angular.json file, results in the Webpack DescriptionFileUtils.loadDescriptionFile() method being invoked for what looks like every dependency in the project. When I leave the "scripts" section blank in angular.json, the number of times DescriptionFileUtils.loadDescriptionFile() is invoked decreases significantly on rebuilds.
13 remaining items
fix(@angular-devkit/build-angular): reduce rebuilt times when using t…
fearghalom commentedon Feb 14, 2023
On rebuilds, it knocked ~35secs off the time.
alan-agius4 commentedon Feb 14, 2023
@fearghalom, thanks for the confirmation.
perf(@angular-devkit/build-angular): reduce rebuilt times when using …
fearghalom commentedon Feb 14, 2023
Another thing I've noticed is that there is a big time lapse between the display of the "√ Browser application bundle generation complete." message and the display of the build stats with the "√ Compiled successfully." message. The build time displayed doesn't seem to reflect the actual time until the build stats are displayed.
The log messages in dev-server\index.js (logger.info) seem to be buffered or something. I added in console.log statements where the "Compiled successfully" message is logged and it was output a lot earlier (over a minute earlier) than the equivalent logger.info statements.
I presume the cache is being updated after the bundles have been generated.
fearghalom commentedon Feb 14, 2023
In the output below, the rebuild time is showing as 16069ms but in the 'Compiled successfully' message isn't displayed until about ~90secs after the code change was made.
perf(@angular-devkit/build-angular): reduce rebuilt times when using …
perf(@angular-devkit/build-angular): reduce rebuilt times when using …
angular-automatic-lock-bot commentedon Mar 17, 2023
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.