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

@istiti did the size of you main bundle increase as well after the update? I've read a report that the angular compiler was being included in bundles which can cause longer builds (this is unintended).

Also cc @ocombe about the i18n error.

filipesilva avatar Oct 19 '18 10:10 filipesilva

@istiti can you try @@angular-devkit/build-angular@~0.10.0 and tell me if the AOT rebuild times are still very long?

filipesilva avatar Oct 19 '18 10:10 filipesilva

@filipesilva not OP, but I'm seeing similar long times with @angular-devkit/build-angular@~0.10.1 as well. Main bundle size increased by ~20%.

hmagrini avatar Oct 19 '18 10:10 hmagrini

@filipesilva main bundle maybe about +0.3mb but maybe this is becasue code size changed... i can't really say it is bigger I find it is not increasing!

right I was with build-angular on 0.9.rc3 after updating using ng udpate --next and didn't realize this build-angular didn't automatically update so after move on 0.10.1 nothing change... same slowdown!

I remove package-lock, remove nodes_modules folder, npm i again on this package file

elvisbegovic avatar Oct 19 '18 10:10 elvisbegovic

EDIT: that size difference between this repro and a new project seemed to be the router, so it didn't actually show a regression.

Original comment below.


@crisbeto provided a reproduction (https://github.com/filipesilva/cli-seven-size-regression) where the size regression can be seen:

$ ng build --prod

Date: 2018-10-19T10:23:51.856Z
Hash: c0ef836735b53b519186
Time: 31168ms
chunk {0} runtime.ec2944dd8b20ec099bf3.js (runtime) 1.44 kB [entry] [rendered]
chunk {1} main.9c9c99a7a2fa8cb359cc.js (main) 259 kB [initial] [rendered]
chunk {2} polyfills.c6871e56cb80756a5498.js (polyfills) 38.4 kB [initial] [rendered]
chunk {3} styles.3bb2a9d4949b7dc120a9.css (styles) 0 bytes [initial] [rendered]

Notice the main bundle is 259kB.

I tried to make a new project and actually couldn't see the regression, the size was pretty much the same as in v6 (170 vs 173kb):

$ ng build --prod

Date: 2018-10-19T10:11:55.402Z
Hash: ec058cf8c6e7c3d3766f
Time: 25655ms
chunk {0} runtime.ec2944dd8b20ec099bf3.js (runtime) 1.44 kB [entry] [rendered]
chunk {1} main.473563a0e53e983e2153.js (main) 173 kB [initial] [rendered]
chunk {2} polyfills.c6871e56cb80756a5498.js (polyfills) 38.4 kB [initial] [rendered]
chunk {3} styles.3bb2a9d4949b7dc120a9.css (styles) 0 bytes [initial] [rendered]

But since I have a repro I can follow up.

filipesilva avatar Oct 19 '18 10:10 filipesilva

I confirm On new green project all seems okay @filipesilva

elvisbegovic avatar Oct 19 '18 10:10 elvisbegovic

My main bundle has gone from 1.33MB to 1.59 MB which makes v7 unuseable, 1.3Mb was already on the limit of what's acceptable and can't really afford it to be any bigger. Where has the extra 0.26MB come from?

dottodot avatar Oct 19 '18 10:10 dottodot

@filipesilva The difference between 173 kB and 259 kB is simply initializing the latter with the router module included. Started two fresh projects to confirm.

skreborn avatar Oct 19 '18 11:10 skreborn

Including the router module apparently adds an extra ~3400 (prettified) lines to the main bundle.

skreborn avatar Oct 19 '18 11:10 skreborn

@dottodot I don't know where those extra 0.26 MB come from but I think they hold the answer to this problem.

Would you be willing to run some tests for me?

The first thing to figure out is if the increased size came from updating Angular itself or the CLI. We can figure that out by updating them separately.

By "Angular itself" I mean all @angular/* dependencies except @angular/cli. For v6 you can use 6.1.7 and for v7 you can use 7.0.0.

By CLI I mean @angular/cli and @angular-devkit/build-angular. For v6 you can use @angular/[email protected] and @angular-devkit/[email protected]. For v7 you can use @angular/[email protected] and @angular-devkit/[email protected].

I assume you're doing a production build. Can you tell me the size of the main bundle for these combinations of dependencies please?

  • Angular v6 and CLI v6
  • Angular v6 and CLI v7
  • Angular v7 and CLI v7

This should help narrow down where the size changed.

filipesilva avatar Oct 19 '18 11:10 filipesilva

@skreborn yeah it took me a while to figure that out, I've edited the original comment to reflect it :/

The size difference must be something else.

filipesilva avatar Oct 19 '18 11:10 filipesilva

@filipesilva no problem will try and get that info together will be a bit later on though.

dottodot avatar Oct 19 '18 11:10 dottodot

@filipesilva

Angular v6 and CLI v6 1.36 MB Angular v6 and CLI v7 1.36 MB Angular v7 and CLI v7 1.59 MB

So I'm assuming that means it's an angular issue rather than cli.

dottodot avatar Oct 19 '18 13:10 dottodot

@dottodot Is the increase in build time similarly noticeable between those versions?

skreborn avatar Oct 19 '18 14:10 skreborn

@crisbeto also reports it happens when updating Angular v6 to v7, while keeping CLI at v7.

I'm trying to get to the bottom of it but it's been really hard what a reproduction. If anyone has a project where they see this and can share, it would really help.

filipesilva avatar Oct 19 '18 14:10 filipesilva

A private project I tried to upgrade did increase in bundle size due to the compiler it looks like being bundled into the production output. I am hoping to try to recreate this is in a isolated small repo. The project is fairly large 60,000+ lines of TS. Here are the images of the webpack bundle analyzer before upgrading to 7 and after.

ng6 0 6

ng7rc

coryrylan avatar Oct 19 '18 14:10 coryrylan

@skreborn Angular v7 and CLI I can only build using the build as I get JavaScript heap out of memory

node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build client --prod

I'll try the builds again and measure the time.

dottodot avatar Oct 19 '18 14:10 dottodot

I'm seeing the same as @coryrylan in my project screen shot 2018-10-19 at 16 36 58 screen shot 2018-10-19 at 16 37 12

Marabyte avatar Oct 19 '18 15:10 Marabyte

Just to give you all an update I've been most day going through the compiled source that @crisbeto provided, but didn't get very far.

All I can say at the moment is that something is pulling in part of the compiler but I can't find what that is. I couldn't find any references that invoked the compiler code by tracing the compiled source.

I have isolated the retained compiler exports though: ConstantPool, LiteralExpr, WrappedNodeExpr, jitExpression, R3ResolvedDependencyType, compileInjector, compileNgModule, compilePipeFromMetadata, makeBindingParser, parseTemplate, compileComponentFromMetadata, compileDirectiveFromMetadata, parseHostBindings, compileInjectable.

I don't yet have a repro that I can debug completely so if someone comes up with one, it would really help.

I'd like to say that I am sorry that this problem slipped through. It is a non trivial problem though, resulting from the interplay between imports on complex applications and dead come elimination. None of the apps and variations I've tried so far fave exhibited this behavior, so I don't think it is trivial to reproduce.

filipesilva avatar Oct 19 '18 16:10 filipesilva

@filipesilva It is worth us posting a list of packages installed to see if there's anything common in each app that it could be attributed to?

dottodot avatar Oct 19 '18 17:10 dottodot