angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Buildtime increased by 50% in v12

Open kemsky opened this issue 5 years ago β€’ 139 comments

🐞 Bug report

Command (mark with an x)

  • [x] build

Description

This is v11.2.13:

$ ng build --prod
√ Browser application bundle generation complete.
√ Copying assets complete.
√ Index html generation complete.

Initial Chunk Files                   | Names         |      Size
main.1bbe17e891e0e81a6bae.js          | main          |   3.20 MB
scripts.5b3322e07a3cdcf6af69.js       | scripts       |   1.48 MB
styles.19406af932cc90ae2667.css       | styles        | 152.44 kB
polyfills-es5.2cb7395a5fd592fe7443.js | polyfills-es5 |  85.88 kB
runtime.23c71f07ba7ec5c3766a.js       | runtime       |   1.51 kB

                                      | Initial Total |   4.92 MB

Build at: 2021-05-14T11:00:10.476Z - Hash: 034e3176df64cbc0b60a - Time: 88357ms

Verbose log (logging itself causes slowdown, unfortunately...): angular11.txt

Angular CLI: 11.2.13
Node: 14.17.0
OS: win32 x64

Angular: 11.2.13
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1102.13
@angular-devkit/build-angular   0.1102.13
@angular-devkit/core            11.2.13
@angular-devkit/schematics      11.2.13
@angular/cdk                    11.2.12
@angular/material               11.2.12
@schematics/angular             11.2.13
@schematics/update              0.1102.13
rxjs                            6.6.7
typescript                      4.1.5

This is v12 with yarn.lock and node_modules removed and reinstalled:

$ ng build --configuration production
Warning: Support was requested for IE 11 in the project's browserslist configuration. IE 11 support is deprecated since Angular v12.
For more information, see https://angular.io/guide/browser-support
√ Browser application bundle generation complete.
√ Copying assets complete.
√ Index html generation complete.

Initial Chunk Files                   | Names         |      Size
main.25755cb56d908f1ffa0c.js          | main          |   3.19 MB
scripts.5b3322e07a3cdcf6af69.js       | scripts       |   1.48 MB
styles.51baf6c2a9fbe6837aa1.css       | styles        | 154.28 kB
polyfills-es5.b787b17c5e8d81a4b18e.js | polyfills-es5 |  90.75 kB
runtime.bf3db8034d6e10a74a56.js       | runtime       |   1.20 kB

                                      | Initial Total |   4.92 MB

Build at: 2021-05-14T11:18:16.175Z - Hash: 8806f0a3a3b1271495e0 - Time: 157125ms

Verbose log (logging itself causes slowdown, unfortunately...): angular12.txt

Angular CLI: 12.0.0
Node: 14.17.0
Package Manager: yarn 1.22.5
OS: win32 x64

Angular: 12.0.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, language-service, material, platform-browser
... platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1200.0
@angular-devkit/build-angular   12.0.0
@angular-devkit/core            12.0.0
@angular-devkit/schematics      12.0.0
@schematics/angular             12.0.0
rxjs                            6.6.7
typescript                      4.2.4

We have a single small *.scss file (overriding some material colors) and it was updated by migration. The application has only one module. I tried removing scss and css from angular.json, but it is still slower than v11.

On average it is 50% slower.

-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
TypeScript                    1011          10391           2652          54543
HTML                           311            629              7           7832
CSS                             66            344             30           2109
Sass                             1             15             14             63
JavaScript                       1              9              3             55
JSON                             1              0              0              3
-------------------------------------------------------------------------------
SUM:                          1391          11388           2706          64605
-------------------------------------------------------------------------------

Recorded profile using node 12:

https://link.nithins.me/s2Uca0Ti

kemsky avatar May 14 '21 12:05 kemsky

@basters Thank you so much! I have successfully opened the v9 and v12 profile (which took several minutes to load, then several minutes to actually show up) and it appears to confirm the findings in other projects as well:

v9:

image

v12 (note: image does not have the same scale as the v9 screenshot!)

image

That orange/yellow-ish in the centre is dart-sass, which wasn't there before.

JoostK avatar May 18 '21 21:05 JoostK

@basters It's also striking that source-map processing is taking significantly more time in v12: 44s versus 8s in v9. I don't know why this is because source-map processing hasn't changed much. It could be that something in the pipeline is producing larger source maps, such that processing them takes a lot longer.

The Babel processing on the other hand is 20% faster in v12, from 40s to 32s (the block with the gazillion colours towards 2/3 of the trace).

Looking at it further, I'm doubting if the exact same sources are being compiled? createProgram takes 17s in v9 versus 27s in v12 and type-checking went from ~10s to ~42s. I am not sure where these large differences come from.

edit: the difference in type-checking is partly explained by the fact that v12 uses TypeScript's incremental type-checking, which is more expensive as it needs to perform extra computations. However, type-checking itself is still 24s, a lot more than the 10s in v9.

JoostK avatar May 18 '21 21:05 JoostK

@JoostK Yep, I'm 100% sure that exact same sources are being compiled. Just double checked and what I can say: only ngx-toastr and ngx-cookie-service were updated to latest versions. Everything else remains the 100% same. If ngx-cookie-service & ngx-toastr can blur the picture - I can revert them to previous versions and record ng12 build profile again, just let me know.

Its important to note that those libraries were updated for ng11 build as well to [email protected] and [email protected]. For ng12 build it is [email protected] and [email protected].

basters avatar May 19 '21 05:05 basters

@basters, are you using @angular/material? if so for is this referenced in SCSS?

alan-agius4 avatar May 19 '21 05:05 alan-agius4

@alan-agius4 yes, I'm using @angular/material and it was updated with ng update as well as angular and it has references in SCSS. Here is a link to theme&palette setup

basters avatar May 19 '21 05:05 basters

Looking at it further, I'm doubting if the exact same sources are being compiled? createProgram takes 17s in v9 versus 27s in v12 and type-checking went from ~10s to ~42s. I am not sure where these large differences come from.

@JoostK, this is likely coming from the fact that in v9 the build was in JIT mode.

alan-agius4 avatar May 19 '21 06:05 alan-agius4

Looking at it further, I'm doubting if the exact same sources are being compiled? createProgram takes 17s in v9 versus 27s in v12 and type-checking went from ~10s to ~42s. I am not sure where these large differences come from.

@JoostK, this is likely coming from the fact that in v9 the build was in JIT mode.

I don't think that's the case; there's Angular analysis and template type-checking in both versions, so they are both using AOT.

JoostK avatar May 19 '21 07:05 JoostK

@JoostK, you are right.

alan-agius4 avatar May 19 '21 08:05 alan-agius4

I wrote a small tool that uses both sass-migrator and migrateFileContent from @angular/material/schematics/ng-update/migrations/theming-api-v12/migration to migrate all scss files to use modules instead. Build times is now "only" increased ~15%.

JonWallsten avatar May 19 '21 08:05 JonWallsten

❯ nx report
  Node : 14.17.0
  OS   : darwin x64
  npm  : 6.14.13
  
  @nrwl/angular : 12.3.3
  @nrwl/cli : 12.3.3
  @nrwl/cypress : 12.3.3
  @nrwl/devkit : 12.3.3
  @nrwl/eslint-plugin-nx : 12.3.3
  @nrwl/express : 12.3.3
  @nrwl/jest : 12.3.3
  @nrwl/linter : 12.3.3
  @nrwl/node : 12.3.3
  @nrwl/tao : 12.3.3
  @nrwl/workspace : 12.3.3
  typescript : 4.2.4

Using Angular Material with "sass": "1.32.13", And using a component lib (tkp-ddm-lib) with Customised Angular Material components (NG 11 non Ivy)

Screenshot 2021-05-19 at 15 27 10

gupo_ng12.cpuprofile.zip

Screenshot 2021-05-19 at 16 03 56

It looks like it is idle for a very long time Screenshot 2021-05-19 at 15 40 17

the-ult avatar May 19 '21 13:05 the-ult

@the-ult, from the profiler at appears that it might be caused by NX. Can you replicate using only the Angular CLI?

alan-agius4 avatar May 19 '21 14:05 alan-agius4

Don't know how atm. Since it automatically uses the nx build command. πŸ€”

Might be related to https://github.com/nrwl/nx/issues/5370

the-ult avatar May 19 '21 14:05 the-ult

Yesterday release (12.0.1) contains several performance improvements. Please give it a try!

alan-agius4 avatar May 20 '21 16:05 alan-agius4

Build is indeed faster (more like V11) πŸ‘ Now: 49.728mswas 156.175ms with v12.0.0

Screenshot 2021-05-20 at 20 30 58

the-ult avatar May 20 '21 18:05 the-ult

I can not confirm that it is faster, it is the same (NG_BUILD_CACHE=0, no scss files):

yarn run v1.22.5
$ ng build --configuration production
Warning: Support was requested for IE 11 in the project's browserslist configuration. IE 11 support is deprecated since Angular v12.
For more information, see https://angular.io/guide/browser-support
√ Browser application bundle generation complete.
√ Copying assets complete.
√ Index html generation complete.

Initial Chunk Files                   | Names         |     Size
main.4005861e09f6e41ffcfa.js          | main          |  3.25 MB
scripts.a1b5cf0dcd279cdb7b01.js       | scripts       |  1.48 MB
polyfills-es5.4c8a7ba5c0469b219d89.js | polyfills-es5 | 90.75 kB
runtime.123c72c8729cb6d2b266.js       | runtime       |  1.20 kB

                                      | Initial Total |  4.82 MB

Build at: 2021-05-20T20:02:02.300Z - Hash: 6163206ae2d71ff8308a - Time: 161921ms

Also, I noticed a huge CPU load at the beginning of the build process: image

Angular CLI: 12.0.1
Node: 14.17.0
Package Manager: yarn 1.22.5
OS: win32 x64

Angular: 12.0.1
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, language-service, material, platform-browser
... platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1200.1
@angular-devkit/build-angular   12.0.1
@angular-devkit/core            12.0.1
@angular-devkit/schematics      12.0.1
@schematics/angular             12.0.1
rxjs                            6.6.7
typescript                      4.2.4

Done in 2.19s.

There is a way to improve performance noticeably: cross-env NODE_OPTIONS=--max_old_space_size=8048 ng build --configuration production builtimes are now 10s less.

kemsky avatar May 20 '21 20:05 kemsky

I've just upgraded a project to 12.0.1 and I'm seeing significant increases in serve/build times. I've recorded profiles of both v11 and v12 and I'm seeing a suspicious gap in v12 where the process is mostly idle .

Angular 12 profile: https://www.file.io/download/tr8wrukOKzKh

grafik

Here's I've zoomed in on a bit in the mostly empty gap section:

grafik

Angular 11 profile for comparison: https://www.file.io/download/3t39VkJLfeat

grafik

cypressious avatar May 21 '21 14:05 cypressious

@cypressious, can you please re-upload the files? I am trying to look into this but I am getting the following error file.io The file you requested has been deleted

alan-agius4 avatar May 21 '21 16:05 alan-agius4

@alan-agius4 please try https://filehorst.de/d/dvgbldhr. Sorry for the crappy file hoster, don't know where else to upload the file.

Alternative link that expires in 7 days: https://www.dropbox.com/t/35SR07Q2zYOTWIYa

cypressious avatar May 21 '21 17:05 cypressious

I've just upgraded a project to 12.0.1 and I'm seeing significant increases in serve/build times. I've recorded profiles of both v11 and v12 and I'm seeing a suspicious gap in v12 where the process is mostly idle .

Angular 12 profile: https://www.file.io/download/tr8wrukOKzKh

grafik

Here's I've zoomed in on a bit in the mostly empty gap section:

grafik

Angular 11 profile for comparison: https://www.file.io/download/3t39VkJLfeat

grafik

Still really slow with 12.0.1 and a breaking Issue with zIndex CSS Parsing

danielehrhardt avatar May 21 '21 19:05 danielehrhardt

@alan-agius4 please try https://filehorst.de/d/dvgbldhr. Sorry for the crappy file hoster, don't know where else to upload the file.

Alternative link that expires in 7 days: https://www.dropbox.com/t/35SR07Q2zYOTWIYa

Is that the full profile? I am seeing a different from the one shown above. Pretty much I am not seeing anything in the first 4 seconds.

Screenshot 2021-05-24 at 07 49 11

alan-agius4 avatar May 24 '21 05:05 alan-agius4