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

v7.0.0 bugs and 4/5x slower serve & compile AOT

Open elvisbegovic opened this issue 8 years ago • 100 comments

I hesitate to open this issue on angular page. I opened same issue title 2 week ago here without AOT : v7.rc.0 serving 2x - 3x slower than stable versions on my projects after moving to angular 7.0.0 all is slower (jit seems OK)

I'm submitting a...

[ x ] Performance issue [ x ] Bugs

Current behavior

All was OK with cli7rc3 and angular 6.1.10 This morning after updating to angular 7.0.0 serving with JIT is ok but serving with AOT or build my application or generating i18n xmb file is 2-3 times slower

Expected behavior

Get build/extract i18n time like with cli7rc3 and angular 6.1.10

1. Minimal info of AOT serving

  1. My project have >1200 files.
  2. Before update node --max-old-space-size=8192 ./node_modules/@angular/cli/bin/ng serve --aot --sourceMap=false --disableHostCheck --port=4200 first build finish in 45seconds and Now blocking:

3mn => 11% building modules 9/10 modules 1 active ...ojects\i10\src\assets\styles\styles.css and rest steps seems ok It finish in 228737ms

  1. Before update refresh(file edit) it finish in 30seconds and 3th refresh in 25seconds and Now it refresh in 200277ms and 3th refresh in WARNING : 381979ms it is >6 minutes

2. Minimal info of extract i18n

  1. Extract is 3-4 times slower than before update

Here is my angular.json config file

I tried debug with ndb and share my profile data with ng s --aot but it seems not work ndb crash ( disk is highly used...): cli

Environment

Angular CLI: 7.0.1
Node: 10.12.0
OS: win32 x64
Angular: 7.0.0
... common, compiler, compiler-cli, core, forms, http
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.10.1
@angular-devkit/build-angular     0.9.0-rc.3
@angular-devkit/build-optimizer   0.9.0-rc.3
@angular-devkit/build-webpack     0.9.0-rc.3
@angular-devkit/core              7.0.1
@angular-devkit/schematics        7.0.1
@angular/cdk                      6.4.7
@angular/cli                      7.0.1
@angular/material                 6.4.7
@ngtools/webpack                  7.0.0-rc.3
@schematics/angular               7.0.1
@schematics/update                0.10.1
rxjs                              6.3.3
typescript                        3.1.3
webpack                           4.19.1

Others: maybe related to : https://github.com/angular/angular/issues/26572 , https://github.com/angular/angular-cli/issues/12645

@filipesilva heya, sorry to make noise again if you consider this as angular compiler problem(as I think) close or move it please

elvisbegovic avatar Oct 19 '18 09:10 elvisbegovic

@dhardtke Nice. Seems like a sensible workaround for now. Thanks!

stevethemacguy avatar Oct 23 '18 20:10 stevethemacguy

@dhardtke Nice work !

100cm avatar Oct 24 '18 02:10 100cm

We discussed a plan yesterday with @mhevery that would allow us to cut the dependency from @angular/core to @angular/compiler by publishing a well-known symbol on window from the latter, and ensuring that either platform-browser-dynamic or maybe a new @angular/core/jit module was loaded first so that the compiler is present before the first Ivy component bootstraps. We are working to prioritize that.

alexeagle avatar Oct 24 '18 12:10 alexeagle

@dhardtke

Is externals a webpack config? where do you put this in an angular cli build?

dereklin avatar Oct 24 '18 20:10 dereklin

I tried to look if there was a way to declare externals with the webpack config used by @angular/cli (https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts) but couldn't find any :( So no, there is no way to do it with @angular/cli.

dhardtke avatar Oct 24 '18 20:10 dhardtke

I tried using https://github.com/meltedspark/angular-builders, but did not help. I have a universal app with lots of lazy modules

zorrme avatar Oct 24 '18 21:10 zorrme

@dereklin See 100cm comment here.

hakimio avatar Oct 25 '18 06:10 hakimio

@filipesilva In typescript version 3.1 and more, was found a bug with performance regression. I think the problem is the same.

Issue: Microsoft/TypeScript#28025 PR: Microsoft/TypeScript#28028

thekiba avatar Oct 25 '18 07:10 thekiba

@thekiba I think the problem you are describing is slightly different, and is the root cause of https://github.com/angular/angular/issues/26674. In fact I'm pretty sure it's the same because both mention moduleNameResolvesToAmbientModuleInNonModifiedFile specificially.

I agree they are similar problems because both affect performance, and affect them with the same dependency changes since Angular 7 depends on TS 3.1. But the TS issue is broader and the issue here needs to also be solved for a full resolution in CLI projects.

filipesilva avatar Oct 25 '18 07:10 filipesilva

https://github.com/angular/angular/pull/26734 will fix this from framework side. We are figuring out if that can go in the next 7.0.x release of Angular to resolve this issue next week.

alexeagle avatar Oct 25 '18 17:10 alexeagle

Our CI build in Azure Pipelines fails with

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

Our smaller apps still build ok, but larger ones are using too much memory for the hosted agents.

Hopefully the combination of fixes for the above mentioned Typescript regression and this framework change will resolve this issue.

seangwright avatar Oct 26 '18 18:10 seangwright

Same here. We have seen that production builds use more memory than in previous versions.

This should be addressed as soon as possible but, in the meantime, you can increase the -max-old-space-size to something around 4gb.

aalbericio avatar Oct 26 '18 18:10 aalbericio

As a note: we have noticed that production builds aren't the only thing that suffer from this. With a sufficiently large application, ~this~ a JS Heap out of memory error (which was how I got to this issue page from #12645 ) happens 100% reliably with the application watcher. Increasing the heap limit as suggested in a few places definitely delays the error, but it looks like there might be a memory leak in the build->watch->detect change->rebuild loop.

It should be noted that it appears to happen mostly in the SourceMapDevToolPlugin step of the rebuild. Not sure how to provide a reproduction as the issue appears to be purely related to the size of the application and number of independent modules. We have multiple projects that this happens on and the smaller (~1650 modules) fails after more rebuilds than our larger (~3400 modules) project with equivalent memory settings.

mko avatar Oct 31 '18 21:10 mko

I agree with @mko. We have a larger app which fails to rebuild when running using ng serve. I identified the problem that compiler.js is included in the bundle. I expected that this PR angular/angular#26734 will fix it but it's merged and as of version 7.0.2 the issue still remains - compiler.js is included in the bundle. This blocks our upgrade to Angular 7.

mordka avatar Nov 01 '18 11:11 mordka

The @angular/[email protected] releaseincludes https://github.com/angular/angular/pull/26734 and I could verify with the repros in https://github.com/angular/angular-cli/issues/12646#issuecomment-432292721 that the compiler is not retained anymore. This should address compiler being retained and part of the longer build time.

On the TS side, Microsoft/TypeScript#28028 is merged but not yet released. We are waiting for it to be released in 3.1.x. When that is out, it should overall address longer build and rebuild times.

filipesilva avatar Nov 01 '18 12:11 filipesilva

@mordka I'm not sure why the compiler is still included in your bundle. I can give you instructions on how to obtain a log that lists the reasons though.

  • first make sure you are using @angular/[email protected], Typescript 3.1.x and CLI 7.x
  • then open node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/stats.js
  • replace the verboseWebpackOutputOptions variable with below:
const verboseWebpackOutputOptions = {
  // The verbose output will most likely be piped to a file, so colors just mess it up.
  colors: false,
  usedExports: true,
  maxModules: Infinity,
  optimizationBailout: true,
  reasons: true,
  children: true,
  assets: true,
  version: true,
  chunkModules: true,
  errorDetails: true,
  moduleTrace: true,
};
  • run ng build --prod --verbose > log.txt

This should make a log showing all the modules and the reasons for their inclusion. File paths will be shown here. Can you send post that log here?

filipesilva avatar Nov 01 '18 12:11 filipesilva

I updated to @angular/[email protected] ng serve --aot works well first time first rebuild is as slow as initial build, second rebuild resulted in CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

The same project with 6.x branch of angular and cli works perfectly for hours of development

quanterion avatar Nov 01 '18 14:11 quanterion

I can confirm that with angular 7.0.2 our bundle size is now almost the same compared to 6.x. With 7.0.1 it was about 300kb more. Main bundle. —prod build is about 2x slower then before from 8min to 16min hope for this typescript fix

elvirdolic avatar Nov 01 '18 15:11 elvirdolic

To add to what is being mentioned about issues with the build/serve, I'm currently running into both slower re-compilation and failing re-compilation.

Here are my package versions.

Angular CLI: 7.0.3
Node: 10.13.0
OS: win32 x64
Angular: 7.0.2
... animations, cdk, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.10.3
@angular-devkit/build-angular     0.10.3
@angular-devkit/build-optimizer   0.10.3
@angular-devkit/build-webpack     0.10.3
@angular-devkit/core              7.0.3
@angular-devkit/schematics        7.0.3
@angular/cli                      7.0.3
@angular/flex-layout              7.0.0-beta.19
@ngtools/webpack                  7.0.3
@schematics/angular               7.0.3
@schematics/update                0.10.3
rxjs                              6.3.3
typescript                        3.1.5
webpack                           4.19.1

My initial ng serve --aot builds correctly but after the first save I see the following result in the console.

i 「wdm」: Compiled successfully.
i 「wdm」: Compiling...

Date: 2018-11-01T15:37:56.029Z - Hash: 50c9f255f7875ecf1705 - Time: 17543ms
17 unchanged chunks

ERROR in Internal Error: The structure of the program changed during codegen.
i 「wdm」: Failed to compile.

seangwright avatar Nov 01 '18 15:11 seangwright

@filipesilva I'm sorry, I forgot to clean package-lock.json and it appears the compiler.js was only in the dev build which is correct. It works now! :confetti_ball:
Builds are not failing and build times are fast again.

To anyone concerned, ensure to rm package-lock.json and rm -rf node-modules. Also followed by ng update @angular/cli @angular/core

mordka avatar Nov 01 '18 16:11 mordka