angular: (AOT bug) Template containing a lot of form controls and compiled with ngc causes webpack builds that are either slow or hang forever

I’m submitting a … (check one with “x”)

[x] bug report => search github for a similar issue or PR before submitting

Current behavior

If you have a lot of form controls in template and compile with AOT, webpack build will hang for a long time or seemingly never complete.

In the below demo of the bug, I have 20 form controls on a template, it will take about 2 minutes to build after compile. If you delete 5 of them, it only take 12 seconds to compile. If you have 30 controls in total, it will hang for an extremely long time or never complete.

Expected behavior

It should be able to compile in a reasonable amount of time regardless of how many form controls used.

Reproduction of the problem

As this is something that can’t be reproduced on plunker, I’ve created a minimal repo that demonstrates the bug:

https://github.com/qdouble/aot-form-controls-build-bug

To demo the bug, just clone the github repo and run npm i to install. To compile and build files, run npm run compile. To create a normal build without ngc, just use npm run build. To start server, use npm run prodserver.

Please tell us about your environment:

  • Angular version: 2.0.0-angular-builds
  • Language: [TypeScript X.X]
  • Node (for AoT issues): node --version = 6.5.0

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 27 (10 by maintainers)

Most upvoted comments

You can reproduce it using tsc only. Generated files lack type information (a lot of any), it makes typescript compiler to do a lot of work to infer or narrow types and it likely to have bug(s) but it is not the case.

You can leave only one file app.ngfactory.ts to make typescript compiler stop. Looks like _View_App0.injectorGetInternal which contains many if statements heavily abuses typescript internal mechanics (too many return points, conditions, i guess compiler can not optimize, i.e. extract invariant). However solved it refactoring out duplicated conditions like:

token === import15.NG_VALUE_ACCESSOR
token === import16.FormControlName
...

ngc should generate compiler friendly code.