You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AOT build fails due to "JavaScript heap out of memory" #5618
What version of the CLI and Angular are you on?
1.5
Does this only happen on ng build --prod?
No, with --aot and --build-optimizer it fails too (see below)
Do you still get the memory error with these build commands:
For the commands that fail, it can be intermittent - ie. fail 4/5 times, but pass on the 5th
ng build --build-optimizer=false: Passes
ng build --aot: Passes
ng build --aot --build-optimizer: Fails
I can get these to pass 100% of the time by increasing the amount of available memory (ie: node --stack_size=4048 node_modules/.bin/ng build --prod | OR by --build-optimizer=false)
I don't think increasing the node --stack_size is a good idea. All that will do is mask the real issue here. The build should not be gobbling up so much memory. There is a fundamental problem that needs to be fixed.
Reacted by Rokas Brazdžionis, Brenden Niedermeyer and Ruben Prins
The issue is not "closed". It's both open and marked urgent.
No one is suggesting that increasing the stack size is a permanent solution
angular-cli developers have chimed in indicating they're taking the issue seriously and requested feedback on which builds were having issues.
If folks want to complain about memory requirements, they can. If folks want to say it's unreasonable this bug exists, they can. If folks want to encourage people to no longer use Angular, they can. The developers are already looking at this, no amount of vitriol will make that faster. In the mean time, add a swap volume, increase the stack size, and subscribe to the issue for updates -- which unfortunately will likely be mostly complaints for a while.
Reacted by Hugo Des, bertrandg, vanroda, seanlandsman, Jiří Balcar, Jinder Sidhu and Hugo Campos
Not sure if this is just my experience or not, but in cases where I had template errors (used a non-public variable in template, used the wrong type for an @Input(), etc.) I would see the memory usage climb really high, and then crash the build. My suggestion is to make extra sure that there are no template errors. This can be done by invoking ngc directly on the project. Not sure if that will help, just sharing my experience.
I've been running a bunch of memory profiles on projects to try and figure out what the cause is. I'm comparing projects using CLI 1.5.0 + Angular 5.0.0 + Typescript 2.4.2 against CLI 1.4.9 + Angular 4.4.6 + Typescript 2.3.2. Special thanks to everyone that provided repros, that helps a lot.
@magemello I'm having some trouble building your project. It seems to be a couple of missing style variables (like $alfresco-typography). I assume I have to build these before the app. Can you tell me what the missing steps are? This is what I did:
git clone https://github.com/Alfresco/alfresco-ng2-components
cd alfresco-ng2-components
cd demo-shell-ng2
git checkout development
npm install
npm run ng -- build --prod --build-optimizer # errors on Undefined variable: "$alfresco-typography".
@seanlandsman I could not reproduce with the repository you linked. I got the same results with 1.4.9 as I did with 1.5.0. Builds seemed to finish in roughly the same amount of time, and consume a maximum of 500 MB of memory. Bundle sizes were also the same (more on that in a second). Can you think of anything I might be missing? I'm on Windows 10, node 8.9.1.
@teabagp using your repro (#8457 (comment)) I saw both a bundle size increase (500kB to 4MB) in 1.5.0 and a memory usage increase (from 580 to 1080 MB). This is the only community repro I really have at the moment, if someone else has a project I can look at please let me know.
The last repro is specially relevant because it shows this problem even in a small project. Those of you that ran into memory problems that went away after increasing the memory limit, can you tell me if your bundles also got significantly bigger?
Based on @teabagp's repro, this is what I can currently say:
this seems to be related to the library used (devextreme and devextreme-angular),
memory usage seems normal up until the "92% asset optimization" phase, then dramatically increases,
switching build optimizer off doesn't change this,
switching to the old uglify doesn't change this,
I don't think it's directly related to the new TS compiler since that runs at the 10% building modules phase and memory usage seems normal then.
At the moment I don't think the 1.5 memory usage increase is directly related to either Build Optimizer or Sourcemaps. Both of these increase memory usage by virtue of doing more thing. So bigger projects should indeed use more memory. We should still keep this under control but for the 1.5 specific problem it doesn't seem to be the root cause.
Those of you that ran into memory problems that went away after increasing the memory limit, can you tell me if your bundles also got significantly bigger?
Yes, main bundle increased by roughly 4MB. Sadly the project isn't open source, but it's pretty complex anyway the other project is a better example to try diagnose I think.
sorry for not providing you more information on how to run it correctly:
cd scripts
./update-version.sh -v 2.0.0-6a24c6ef754f24212bdd7120d5cdbe47b83c3432
cd ..
cd demo-shell-ng2
npm install
npm run ng -- build --prod --build-optimizer
> Alfresco-Angular2-Demo@1.10.0-beta6 ng /Users/mromano/dev/alfresco-ng2-components/demo-shell-ng2
> ng "build" "--prod" "--build-optimizer"
92% chunk asset optimization
@magemello I'm on windows and unfortunately that script doesn't seem to be very windows friendly even with gitbash...
kamik@T460p MINGW64 /d/sandbox/memory/alfresco-1.4/scripts (development)
$ ./update-version.sh -v 2.0.0-6a24c6ef754f24212bdd7120d5cdbe47b83c3432
====== New version 2.0.0-6a24c6ef754f24212bdd7120d5cdbe47b83c3432 =====
====== UPDATE COMPONENTS ======
====== clean lock file ng2-alfresco-core ======
rm: cannot remove '/d/sandbox/memory/alfresco-1.4/scripts/../ng2-components/ng2-alfresco-core/package-lock.json': No such file or directory
====== UPDATE COMPONENT ng2-alfresco-core ======
====== UPDATE PACKAGE VERSION of to 2.0.0-6a24c6ef754f24212bdd7120d5cdbe47b83c3432 version in all the package.json ======
sed: can't read s/"version": "[0-9]\.[0-9]\.[0-9]"/"version": "2.0.0-6a24c6ef754f24212bdd7120d5cdbe47b83c3432"/g: No such file or directory
====== UPDATE DEPENDENCY VERSION of ng2-alfresco-core to ~2.0.0-6a24c6ef754f24212bdd7120d5cdbe47b83c3432 in ng2-alfresco-core======
sed: can't read s/"ng2-alfresco-core": "[0-9]\.[0-9]\.[0-9]"/"ng2-alfresco-core": "2.0.0-6a24c6ef754f24212bdd7120d5cdbe47b83c3432"/g: No such file or directory
sed: can't read s/"ng2-alfresco-core": "~[0-9]\.[0-9]\.[0-9]"/"ng2-alfresco-core": "~2.0.0-6a24c6ef754f24212bdd7120d5cdbe47b83c3432"/g: No such file or directory
====== UPDATE DEPENDENCY VERSION of ng2-alfresco-datatable to ~2.0.0-6a24c6ef754f24212bdd7120d5cdbe47b83c3432 in ng2-alfresco-core======
sed: can't read s/"ng2-alfresco-datatable": "[0-9]\.[0-9]\.[0-9]"/"ng2-alfresco-datatable": "2.0.0-6a24c6ef754f24212bdd7120d5cdbe47b83c3432"/g: No such file or directory
sed: can't read s/"ng2-alfresco-datatable": "~[0-9]\.[0-9]\.[0-9]"/"ng2-alfresco-datatable": "~2.0.0-6a24c6ef754f24212bdd7120d5cdbe47b83c3432"/g: No such file or directory
====== UPDATE DEPENDENCY VERSION of ng2-alfresco-upload to ~2.0.0-6a24c6ef754f24212bdd7120d5cdbe47b83c3432 in ng2-alfresco-core======
sed: can't read s/"ng2-alfresco-upload": "[0-9]\.[0-9]\.[0-9]"/"ng2-alfresco-upload": "2.0.0-6a24c6ef754f24212bdd7120d5cdbe47b83c3432"/g: No such file or directory
sed: can't read s/"ng2-alfresco-upload": "~[0-9]\.[0-9]\.[0-9]"/"ng2-alfresco-upload": "~2.0.0-6a24c6ef754f24212bdd7120d5cdbe47b83c3432"/g: No such file or directory
====== UPDATE DEPENDENCY VERSION of ng2-activiti-diagrams to ~2.0.0-6a24c6ef754f24212bdd7120d5cdbe47b83c3432 in ng2-alfresco-core======
sed: can't read s/"ng2-activiti-diagrams": "[0-9]\.[0-9]\.[0-9]"/"ng2-activiti-diagrams": "2.0.0-6a24c6ef754f24212bdd7120d5cdbe47b83c3432"/g: No such file or directory
Is there something I can do even if hacky to get around the need for it? Ideally without removing the global styles as I'm also investigating if style processing is using a lot of memory.
@filipesilva
We started experiencing this pretty significantly in CLI 1.3 & it got worse with 1.4 and so we downgraded to 1.2.6 and haven't had any problems since. we're still running ng 4.4.6 with cli 1.2.6 and it seems fine with default settings.
I don't have a ton of time to dig into this right now so i'm sorry this won't be super helpful but just wanted to let you know where the version numbers went wrong.
We are locked into the following specific versions (along with material 2.0.0-beta.12). if we change JUST cli to 1.3 or 1.4 (and presumably 1.5) we see the issue:
I've just tried on a clean install and it still fails for me. I'm on OSX Sierra and am running node v7.7.3
I also note that if I run ng build --prod --build-optimizer=false it will run successfully repeatedly, whereas running just ng build --prod will fail most of the time.
I'm not sure what I can add here - is there some sort of profiling I can run on my side and provide the output?
this is also affecting me, using angular 5 and cli 1.5, ive had to switch off the build optimizer to get my builds to pass without a out of memory error :(
With "node --stack_size=4048 node_modules/.bin/ng build --prod" I get:
1.4K 14 Nov 20:43 inline.aa760cefdeaeea9e038f.bundle.js
835K 14 Nov 20:43 main.05e5301d42766024fc03.bundle.js
60K 14 Nov 20:43 polyfills.e6475d2787bb3154d59c.bundle.js
48K 14 Nov 20:43 styles.9b2fb464224d0a79781d.bundle.css
With "./node_modules/.bin/ng build --prod --build-optimizer=false" I get:
1.4K 14 Nov 20:45 inline.d7125ae6ed51e3e3af81.bundle.js
4.9K 14 Nov 20:45 main.47d0056e07ee5cb9c483.bundle.js
60K 14 Nov 20:45 polyfills.ad37cd45a71cb38eee76.bundle.js
48K 14 Nov 20:45 styles.9b2fb464224d0a79781d.bundle.css
951K 14 Nov 20:45 vendor.799da157f41ee457e4bd.bundle.js
Interestingly you can see the main.xx.js got much bigger with in the first run, but the vendor file disappeared. This might be expected?
One further bit of information - I just tried this on an older Mac running El Capitan (node version v7.7.3) that I've not used for a while. When I run "node_modules/.bin/ng build --prod" it runs just fine, repeatedly, and much faster than on my current machine. Hopefully this is helpful.
@filipesilva our build also got increased by 3MB or 4MB like the last example you said, taking a long time after the 92%, and we also use the devextreme libraries. Can't share the project repo unfortunately but I could provide our package.json if neeeded.
@filipesilva try to reduce the stack_size to reproduce the @seanlandsman case. node --stack_size=512 node_modules/.bin/ng build --prod gets me that error on my mac.
@filipesilva
What version of the CLI and Angular are you on?
1.5 and 5.0.0 respectivley
Does this only happen on ng build --prod?
Only when the --aot flag is use.
Do you still get the memory error with these build commands:
ng build --build-optimizer=false
no
ng build --aot
yes
ng build --aot --build-optimizer
yes
If you have a project that I can look at, can you link it please?
Sorry, but our application is private per our corporate requirements.
I have the same problem. I also recognized that the size of my application with ng serve drastically increased after the update to angular 5. With angular 4 the vendor.bundle.js created by ng serve used to be 10MB and with angular 5 it is now 30MB.
ng serve -> works
ng build -> works
ng build --prod -> fails
ng build --prod --build-optimizer=false -> fails
ng build --aot -> fails
ng build --aot --build-optimizer=false -> fails
@filipesilva we all could also help debugging the webpack build, what tool are you using to debug it?
I was trying like that, but I'm not sure is the best way:
Heya, using the repros you all provided I believe I've found the main problem with 1.5. It has to do with how the new pipeline moved decorator removal into Build Optimizer.
For those interested in a more detailed explanation, this is what happens:
When you build with --aot, we use TypeScript transforms in Build Optimizer to remove Angular decorators (stuff like @Component and @NgModule) from both your app and libraries (they aren't needed after AOT).
In 1.4 we didn't use Build Optimizer for that, we used manual removal on your app only.
Due to a bug, decorators are removed but their imports stay in the code.
These imports make some third party libs be wholly included, instead of only partially included.
You can check this yourself by comparing ng build --aot when using CLI1.4.9+NG4 versus CLI1.5.0+NG5.
In the devextreme lib case, there was almost 9megs of extra code included.
Extra code means a lot more work for Uglify, which makes it consume a lot more memory.
There might be more factors contributing to the excessive memory usage but currently this is the approach I'm following as it's the most promising one. I hope to have a PR with a fix soon.
Reacted by Jiří Balcar, Denys Vuika, Maurizio Vitale, Mario Romano, radoslavpetranov, Chang Liu, bertrandg, Stanimira Vlaeva, Rokas Brazdžionis, PeS82 and 14 more
Reacted by Lars Naurath, seanlandsman, Marçal, Evan Koehler, Gabriel Carmo, JaredPhelpsInktavo, Sameer Singh, Joseph Brasch and Nehal Damania
@filipesilva awesome news! Thanks for sharing your progress - very much appreciated!
Some of us are experiencing this in non-latest-version setups and others all the way back in cli 1.2 and 1.3 setups. Do you believe this is just a natural limitation and expected behavior due to the size of the projects/dependencies? Is the default <2GB RAM allocation just naturally too small for compiling bigger projects?
@radoslavpetranov I have been thinking about that (@randyaa said the same thing as you), and trying to figure out what a good approach is.
Something that springs to mind is to split up into multiple processes. But upon further scrutiny that approach doesn't really help in the memory usage problem, since multiple process will use at least the same total memory, probably more due to inefficiencies and duplication.
The 1.5 problem highlighted how much Build Optimizer actually helps keep memory usage down by trimming imports (and thus project size). So maybe that's an overall better approach. It does imply that a project must be able to use Build Optimizer though, and there might still be problems with it (code manipulation is tricky).
Another approach might be to took a look at the Uglify memory usage in large bundles. Maybe there room for config tuning or something. But it's hard to say since those tools really rely on a semantic understanding of code bundles to work, so one does expect a lot of memory used on larger bundles.
Something else that I've been thinking about is to actually have a low memory setting, where disk/cpu/total time is traded for a smaller memory footprint. This is just a very high level idea that I haven't explored at all. It would help on limited environments like CI, whereas for dev environments you really want the tradeoffs that give you better rebuild/speeds instead.
For really large projects you just can't get around the fact there are more performant languages than JS and that build tools that can use them effectively (like Bazel) will offer a better experience.
Reacted by radoslavpetranov, seanlandsman, Marçal, Eric Lloyd, Gabriel Carmo, Hugo Campos and Lucas Basquerotto
@filipesilva - Thanks for investigating this. Here's another data point, fwiw:
What version of the CLI and Angular are you on?
1.5.0 and 5.0.0 Does this only happen on ng build --prod?
Seems to be building fine without the --prod flag
Do you still get the memory error with these build commands:
ng build --build-optimizer=false
no ng build --aot
no ng build --aot --build-optimizer
no
If you have a project that I can look at, can you link it please?
Sorry, private repository and project
@filipesilva Thanks for the update and explanation, however we experience this with our projects using cli 1.4.7 and angular 4.4.5 (and early versions too). Currently to build our production version we use the following:
ng build --environment=prod --aot --sourcemaps=false --base-href=\"/ui/\" --preserve-symlinks --output-hashing=all --extract-css=true
We then pass the output to Uglify to minify and mangle the JS and CSS. This process works correctly and we do not hit memory issues, but when we build with ng build --prod that is when we run into memory issues.
We also do not have the devextreme lib. I can't share our code, but I'm happy to install other versions of the CLI and post build results from different commands. Our application is approx 450 components and 290 modules.
Hello @filipesilva
I don't know exactly if this my comment might be useful, but I will report some tests that I did.
I have an angular-cli (1.4.1), angular (4.4.4), typescript (2.3.4) project.
This project contains approximately 200 services and more than 700 components, distributed in at least 15 modules.
When running ng build --prod I noticed a few things.
In this specific project, 0 to 1.9 GB of memory occurs up to the first 10% of the compilation.
(I'm using the saas files from bootstrap).
From the 11% up to the 89% compilation, my memory goes up to less than 3 GB.
From 90% to 92% the memory is used in 4.6 GB.
And finally at 95% the consumption goes up to the maximum limit allowed.
In my case now, up to the 6 GB of RAM I've bound.
To make it compile, I had to configure virtual memory (swap).
I have only 8 GB RAM.
I increased to 12 GB, 16 GB, until finally I was able to compile the project by setting 32 GB RAM.
Consumption of NodeJS hit 28 GB at these same 95% emitting.
Unfortunately this project is private and would not be able to make it available.
Tests requested:
ng build --build-optimizer=false works! 1.5 GB max.
ng build --aot error!
To try to help, I created a very simple project.
In it, there are 10 modules created.
In each module, there are 50 components created.
In each component there is only one HTML with output "works!".
There is no CSS, there is no third-party npm component.
A simple project like this is consuming 1.6 GB of RAM for the AOT build.
I believe that consumption is a little high because it contains absolutely nothing in the project.
If you wanted to download the repository to test, it is zipped in the link below. http://www.codegenerator.com.br/downloads/ng-heap-memory.zip
Thanks in advance for your help.
Reacted by radoslavpetranov, Eric Lloyd, Filipe Silva, Lucas Basquerotto and zhantewei
I've put up a PR that should specifically address the memory usage regression when using 1.5 (#8506). Once it's merged and released I'll ping you all here to see if it helped across your projects.
@tolitech your report of how memory usage changed with build stage was very interesting and useful. Below the 92% stage what happens is TypeScript compilation and loading files into Webpack. After that it's mostly Uglify and Build-Optimizer.
But since you are on 1.4.1 you shouldn't have Build Optimizer by default with --prod. Just to double check, can you confirm that you are not using --build-optimizer?
In your report you mention using what I consider a large project (200 services and 700 components). Definitely not the largest around but still big. I'm not surprised at a 3GB memory usage for TS compilation and loading all app files.
But when it starts getting really bad is after that, when you end up needing at least 28GB at the 92% phase. This to me tells me the bottleneck is Uglify, or maybe some other part of our build pipeline that I'm not seeing right now. But it definitely bears investigating, which I'll do.
Running the small ng-heap-memory project as is I saw a maximum of 1.4GB ram being used. Using the PR this dropped to around 800MB, so it seems to be helping there. I agree that the 500 components are essentially empty, but it doesn't surprise me that just the sheer number of them causes high memory consumption on a build. It's a valuable example by the way, and thank you for making it.
@mattem that's a very interesting approach, and doubly interesting is that you don't suffer much memory issues with it. Can I ask you to give me some concrete numbers for comparison please? Maximum memory usage on a CLI prod build versus CLI non-prod plus manual Uglify. I'd also like to know your uglify version and settings please.
@filipesilva Using ng build --prod gave the OOM error, however running the CLI with node --max_old_space_size=8192 it did complete, with the following memory usage (observed from looking at Activity Monitor in MacOS):
~ 14% 800mb real / 5.5gb virtual
~ 69% 1.5gb real / 6.4gb virtual
~ 90% 1.8gb real / 6.65gb virtual
~ 92% 2.3gb real / 7gb virtual
~ 94% 2.6gb real / 7.12gb virtual
Running with ng build --environment=prod --aot --sourcemaps=false --base-href="/ui/" --preserve-symlinks --output-hashing=all --extract-css=true (no increasing max_old_space) tops out at 1.49gb real / 6.23gb virtual. This is running with @angular/cli@1.4.7 and @angular/*@4.4.5
We use gulp-uglify@3.0.0, giving us uglify-js@3.0.28, setting compress and mangle to true.
The output is also run though loose-envify, uglifycss, and htmlmin
The gulp task peaks at 868mb real / 5.57gb virtual.
According to changelog the above mentioned fix is included in 1.5.1+. It still fails for ng build --prod with 1.5.2 :(
95% emitting
<--- Last few GCs --->
[4980:000001B75DBAB8D0] 268298 ms: Mark-sweep 1399.5 (1698.5) -> 1399.5 (1698.5) MB, 483.4 / 0.0 ms allocation failure GC in old space requested
[4980:000001B75DBAB8D0] 268868 ms: Mark-sweep 1399.5 (1698.5) -> 1399.5 (1629.5) MB, 569.7 / 0.0 ms last resort GC in old space requested
[4980:000001B75DBAB8D0] 269387 ms: Mark-sweep 1399.5 (1629.5) -> 1399.5 (1600.0) MB, 518.8 / 0.0 ms last resort GC in old space requested
Hey all, 1.5.2 includes the fix for the 1.5 memory usage regression. This should help users that had projects that did not have memory problems on 1.4 but started having them in 1.5.
Projects that were already having memory problems in 1.4 should see no change. I'm still looking into the balooning memory requirements for the 92% bundle optimizing phase.
@PeS82@jayhamilton@finalxcode you reported that you're still running into memory problems with 1.5.2. Was this on projects that did not have memory problems in 1.4.x?
@filipesilva With angular cli 1.4.x it used to work, then when i upgrade angular/cli to 1.5.2, it have memory problems, i have to use command node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod --aot to build
@filipesilva@JackArlington same for me. Our project used to build (prod) on 1.4.x and since 1.5.0 does not anymore. 1.5.2 didnot improve the situation. When I increase the memory limit it does compile, but uses aprox 5GB on emitting.
On a side not the huge memory consuption occurs on "95% emitting"
@filipesilva@Shadowlauch I have just recognized that the machine I tested before had node 6.x upgrading it to 8.9.1 solved the problem and ng build --prod --aot works now.
Thank you for the help.
To be clear, I am not aware of any memory issue related specifically to Node 6. I have been testing with Node 8.9.1 myself because I couldn't get memory timelines using Chrome Devtools with Node 6.
Maybe that's part of the equation here... I expect newer nodes to be faster and more memory efficient but perhaps there's more to it.
For instance, I couldn't repro the problem on @seanlandsman's project. @seanlandsman what version of node were you using?
@filipesilva
I do not get heap out of memory error anymore with cli 1.5.2. My node version is 7.5.0.
However the build still takes about 8 - 10 minutes to finish.
@seanlandsman I tested your repros again with --stack_size=512 and --stack-size=8048 and only saw memory consumption in the 400-500MB range. The default seems to be --stack_size=984 btw.
I did see something else though:
kamik@T460p MINGW64 /d/sandbox/memory/aggrid-1.5 (master)
$ npm run prod
> test-ag-grid@0.0.0 prod D:\sandbox\memory\aggrid-1.5
> node --stack_size=512 ./node_modules/@angular/cli/bin/ng build --prod
Date: 2017-11-17T10:46:12.052Z
Hash: db122ac832a501fd0cf8
Time: 31443ms
chunk {0} main.67d8219d9d4c87c59477.bundle.js (main) 830 kB [initial] [rendered]
chunk {1} polyfills.e6475d2787bb3154d59c.bundle.js (polyfills) 61.1 kB [initial] [rendered]
chunk {2} styles.9b2fb464224d0a79781d.bundle.css (styles) 49 kB [initial] [rendered]
chunk {3} inline.d67e755da47b31497a24.bundle.js (inline) 1.45 kB [entry] [rendered]
ERROR in ./node_modules/ag-grid/dist/lib/gridOptionsWrapper.js
Module build failed: RangeError: Maximum call stack size exceeded
at getJSDocsWorker (D:\sandbox\memory\aggrid-1.5\node_modules\typescript\lib\typescript.js:8167:33)
at getJSDocs (D:\sandbox\memory\aggrid-1.5\node_modules\typescript\lib\typescript.js:8163:13)
at getJSDocTags (D:\sandbox\memory\aggrid-1.5\node_modules\typescript\lib\typescript.js:8148:27)
at getJSDocParameterTags (D:\sandbox\memory\aggrid-1.5\node_modules\typescript\lib\typescript.js:8213:20)
at Object.isRestParameter (D:\sandbox\memory\aggrid-1.5\node_modules\typescript\lib\typescript.js:8295:28)
at symbolToParameterDeclaration (D:\sandbox\memory\aggrid-1.5\node_modules\typescript\lib\typescript.js:29262:41)
at D:\sandbox\memory\aggrid-1.5\node_modules\typescript\lib\typescript.js:29215:89
at Array.map (<anonymous>)
at signatureToSignatureDeclarationHelper (D:\sandbox\memory\aggrid-1.5\node_modules\typescript\lib\typescript.js:29215:55)
at createTypeNodeFromObjectType (D:\sandbox\memory\aggrid-1.5\node_modules\typescript\lib\typescript.js:29024:49)
at createAnonymousTypeNode (D:\sandbox\memory\aggrid-1.5\node_modules\typescript\lib\typescript.js:28988:42)
at typeToTypeNodeHelper (D:\sandbox\memory\aggrid-1.5\node_modules\typescript\lib\typescript.js:28938:28)
at createTypeNodesFromResolvedType (D:\sandbox\memory\aggrid-1.5\node_modules\typescript\lib\typescript.js:29177:67)
at createTypeNodeFromObjectType (D:\sandbox\memory\aggrid-1.5\node_modules\typescript\lib\typescript.js:29035:35)
at createAnonymousTypeNode (D:\sandbox\memory\aggrid-1.5\node_modules\typescript\lib\typescript.js:28988:42)
at typeToTypeNodeHelper (D:\sandbox\memory\aggrid-1.5\node_modules\typescript\lib\typescript.js:28938:28)
@ ./node_modules/ag-grid/dist/lib/columnController/columnUtils.js 11:27-59
@ ./node_modules/ag-grid/main.js
@ ./node_modules/ag-grid-angular/dist/ng2FrameworkFactory.js
@ ./src/app/app.component.ngfactory.js
@ ./src/app/app.module.ngfactory.js
@ ./src/main.ts
@ multi ./src/main.ts
This seems consistent with what --stack-size actually does (nodejs/node#6360). It doesn't increase total available memory, but rather the the size of each stack region that node uses. It that increasing it can solve issues with a lot of recursion (but that code should try to not have that).
The symptoms seem to be different on OSX (memory bust) and Windows (maximum call stack size exceeded). I don't know why that is.
I think the problem you're experiencing is solely related to Build Optimizer as you posited, and is the one tracked in angular/devkit#240. Still relevant for this thread mind you, but the specific issue is that one.
@changLiuUNSW were your build times with 1.4.x shorter, and if so, by how much?
@magemello I'll ping you on the gitter you provided and see what we can do in your project.
So, in general raise the max_old_space_size fix my issue at exception of the "ng build --prod", in this case my problem seems to be related to this: angular/angular#20115.
In other words the problem seems to be the presence of ts files in my libraries and aot geting angry about it :), the solution for this point seems to be put ts file in the .npmignore and exclude it from the packages. (haven't test it yet)
I'm just reporting the finding, hopying it helps others....all the credit goes to @filipesilva.
@changLiuUNSW@tolitech can I ask you to do some more advanced debugging if you have time? I don't have access to your projects but they seem good examples.
@changLiuUNSW Your project doesn't seem to have memory problems anymore but it is taking very long to build with Build Optimizer.
I think one of the build optimizer transformations is taking a very long time on your codebase, but I can't know which ones. I can tell you how to disable each one individually though.
You can do this in ./node_modules/@angular-devkit/build-optimizer/src/build-optimizer/build-optimizer.js. From line 63 to line 82, each transform is individually added to the getTransforms array. You can comment out each of the getTransforms.push( and that transform will not be added.
If you can do this for each one and time me how it impacts build time, I might be able to figure out which of the transforms is taking too long.
@tolitech your project has problems with memory usage with 1.4.x, and you have already confirmed it does not use build optimizer. You reported that memory usage went up to 28gigs during a prod build.
I'd like to ask you to do a couple of things. First, can you tell me the memory usage of just ng build please?
Then, I'd like you to try to manually disable Uglify. This can be done in ./node_modules/@angular/cli/models/webpack-configs/production.js, line 111-117 (the new webpack.optimize.UglifyJsPlugin({ call). Comment those lines, and try to do a production build again (with increased memory limits). What was the maximum memory used?
I understand that debugging these things take time and appreciate that you take the time to do it. I'm doing the same things on projects I have access to but each project is different so it's very difficult to zone in on the exact issue without having access to the code. Asking you to do some tests is the next best thing.
took nearly 10 minutes but the build did complete and didn't exceed the 1.3GB RAM mark now. By the looks of it, the bundle also decreased in size. Before I was getting a main bundle of 1.98 MB and a vendor bundle of 1.51 MB and now I only seem to have a single main bundle of 2.49MB.
The dev bundle went from vendor 16MB and main 4.61MB to vendor 5.91MB and main 1.87MB and it didn't exceed the 800MB RAM mark.
@filipesilva I was looking at the package.json for Angular: "engines": { "node": ">=6.9.5 <7.0.0", "npm": ">=3.10.7 <4.0.0", "yarn": ">=1.0.2 <2.0.0" },
I've always taken the engines section to mean that those were the engines supported. Is running Node 8 officially supported or am I reading this all wrong?
Well, interestingly, node 8.9.1 did complete the bundle nearly twice as fast (~5min 50 seconds) compared to node 6.11 and it did use about ~150-200MB less ram throughout the final (92%-95%) stages of the process.
So although the compilation time reduction was very nice, the node version doesn't seem to play a major role in the RAM consumption issue (at least on my machine/project).
EDIT:
Running ng build --aot --prod --build-optimizer=false finished 3 times faster than ng build --aot --prod but it did use about 150-200MB more RAM.
Hello @filipesilva
I've done some more tests and would like to share it with you.
To be a fair test, I restarted my laptop at all times when I changed a line in the production.js file and after running ng build -prod.
In all tests, the virtual memory added was 32 GB.
The laptop has 8 GB physical RAM.
In the ng.cmd file the configured command was --max_old_space_size = 32768 in all cases.
It is important to remember that in this test, the total memory allocated is not exactly the total memory required by Node.js, since it would be the total used by the computer in all of its processes.
However, there was no program or process running, and in all tests the computer was restarted.
Let's go to the tests:
Test 1
Configuration:
Total memory allocated by the computer: 36.5 GB
Waiting time to complete: 26 min 24 secs
Test 2
Configuration:
Total memory allocated by the computer: 34 GB
Waiting time to complete: 20 min 52 secs
Test 3
Configuration:
Total memory allocated by the computer: 7.9 GB
Waiting time to complete: 10 min 03 secs
Test 4
Configuration:
Total memory allocated by the computer: 8.8 GB
Waiting time to complete: 13 min 59 secs
Node v8.9.1
Angular CLI 1.4.1
By my tests, I have to conclude that in my specific case, it is the new webpack.optimize.ModuleConcatenationPlugin() command line that is dramatically increasing my memory need.
With this line enabled, my consumption goes from 8.8 GB to 36.5 GB as indicated by the windows task manager.
If you need more tests, just give me instructions.
I work more with .NET, but with instructions I believe I can test.
Thank you.
Reacted by Mario Romano, Filipe Silva, elclanrs, Alva Chien (Hongjun Qian), Lucas Basquerotto and Richard Durazo
it enables smaller bundles when used with Uglify and Build Optimizer
But it also seems to be causing excessive memory usage in some cases.
I'm a bit at a loss at what I can do about this now. ModuleConcatenationPlugin might use a lot of memory by design or it might just be a bug, but it's hard to tell without being able to test it myself.
To users that started having memory problems after the 1.3x update: can you try doing a build disabling ModuleConcatenationPlugin manually (same instructions as I gave @tolitech in #5618 (comment)) and tell me if it helps? If it does help and your project is public, can you tell me where I can see it?
@alvachien I tried your project with 1.5.2 and it ng build --prod built correctly with a peak of 1.2GB memory usage. Did you try 1.5.2? There's a fix there that isn't in 1.5.0.
@markmaynard what you're looking at is the the package.json for the angular/angular repo: https://github.com/angular/angular/blob/master/package.json#L10-L13. That repro is what we call a monorepo, where multiple packages are under the same repository. The engine requirements you see there are for the monorepro itself: the requirements to build the Angular packages. But not the requirements for using the Angular packages. If you check out package.json for @angular/core (in your node_modules for instance), there won't be any engine requirements.
@mattem@WandererInVoids I tried running a few experiments in a project with a lot of libs, to compare memory usage with and without a separate Uglify process:
ng build --prod: peak 1.1GB memory, 4.1MB main bundle
ng build --prod with Uglify manually commented off: peak 0.8GB memory, 10.5MB main bundle
Uglify ran manually on main bundle: peak 0.7GB memory, 4.2MB uglified main bundle
CLI used was 1.5.2. It's important to note that I used the same Uglify we use in the CLI (uglify-es@3.1.5, the one included by uglifyjs-webpack-plugin@1.0.0), and that I also used the same flags we use in the CLI: --compress pure_getters,passes=3 --mangle.
Flags here are really important because these affect the memory usage and end result. See mishoo/UglifyJS#2113 for some conversation about memory usage in Uglify.
From the numbers I got I wouldn't say there is a problem with how we use Uglify. The difference (1.1GB vs 0.8+0.7) is larger than each process individually but is smaller than both together. I expect this to be because of all the files/sourcemaps loaded into memory.
But it's worth mentioning that by not running --prod you are also not running ModuleConcatenationPlugin. Maybe in your projects that's the actual problem and not Uglify. Can you try disabling as well? (see #5618 (comment) on how to disable it).
Hello @filipesilva
I have tried to create a very similar model of what I use so that the tests can be performed with greater precision.
In this application there are basically 5 main pages (category, status, severity, project and issue) that are replicated 10 times within the same module. We have 50 pages per module. 10 modules totaling 500 pages were created.
For me, a page is composed of 3 components, the entry point, the grid and the form.
So we have 1,500 components created.
There are several other components created and used by the application, base components that are inherited via typescript, pagination, menu, security, shared module, directives, guards, models, resolvers, among other elements.
Not all npm referenced libraries are being used in this example, but I believe the model is quite useful for testing.
In this example, my maximum memory consumption hit 23 GB.
Somewhat below my actual case, because although this example has many more components, the components created in my real case are more complex.
I do not know if I exaggerated the number of elements created for the test.
Although hundreds of services have been created (one for each page), all modules and page replications call the same five Api urls (category, status, severity, project and issue).
@tolitech whoa this is perfect, thank you so much! I'll use it to run some benchmarks and see what I can find. Will also try and trim it down to do a webpack issue for ModuleConcatenationPlugin so we can get the ball rolling there. This is great!
Note: using CLI 1.5 + Angular 5 defaults to using Build Optimizer on prod builds. I also noticed that the 92% phase took a lot longer than before like @changLiuUNSW reported, while memory usage kinda plateaued. It makes me think that PurifyPlugin (part of Build Optimizer) is what takes so long here.
For comparison, I also tried compiling the project using ngc and it peaked at 3.3gb used memory. Comparing that to the 0-11% phase it looks like our compiler plugin doesn't add a significant overhead. tsc itself peaks 830MB used memory.
Looking at the peak memory usage numbers I can say a couple of things:
Memory usage from compilation (0-11% phase) seems reasonable for project size.
The 11%-89% phase takes a while loading everything but it's also not very surprising.
I expected the 90%-94% phase to take the lion's share of memory usage but that wasn't the case at all.
The 95-100% phase is where memory is being massively used up.
I'm going to follow up with the Webpack folks to see what's actually happening in that last phase.
@tolitech you've been a massive help getting to the bottom of this, I can't thank you enough 💯
Reacted by bertrandg, Eduardo Tolino, Adam Wamai Egesa, AndreaBarbasso, WandererInVoids, Randy Aldrich, Alva Chien (Hongjun Qian), João Almeida, Lucas Basquerotto and Brian Troncone
I don't get how 3.3 Gb memory for 1500 HTML files is reasonable. That's 2 Mb per file. Do these numbers contain collectable garbage or is this what's actually claimed until the end of the build?
@Tragetaschen it's not just the HTML files, it's all the TS and code transformations too. The amount of memory used by the plugin (which is developed in this repo) is reasonable insofar as it is not a big overhead, 3 vs 3.3gb, over the ngc compiler itself (which is developed in angular/angular).
Taking advantage of the moment, I do not know if this would be the best time, but is there any technique for development to be improved?
Example: In a large project like this, a simple change in HTML or TS ends up taking a long time to reflect the onscreen settings. (ng serve -o running).
@tolitech I'd like to talk about the different factors influencing dev rebuilds in big projects but would much prefer to do it in a separate issue. It's something that gets asked about frequently and it would be good to have discussion on it.
Can you open an issue called "Total rebuild time in medium and large projects", share your experience (rebuild time in the console but also time until app is ready in the browser), and ping me there please?
Reacted by Eduardo Tolino, Matt Mackay and Adam Wamai Egesa
@filipesilva I have tried commenting out the ModuleConcaternationPlugin and rerun our builds. In short our project still runs into memory issues.
I don't know if this makes a difference, but the way our projects are currently setup we have a number of internal libraries that while in development, use npm link to link.
Memory peaks at 2.51gb real / 7.26 virtual when running with the ModuleConcaternationPlugin commented out.
Full output:
The build completed without the need to add additional memory to Node.
I also tried running with node --inspect and attaching the Chrome debugger to grab some heap snapshots and memory profiles, but it in my tests that caused the CLI to hang during the compilation stage with 1 module remaining.
The other part that is hammering us is the time taken by the compile for tests, we have had to continually increase timeouts in the Karma conf, and the time taken for a page refresh with tests (during development) is quite high, mainly due to that ~15mb vendor bundle.
@filipesilva I get that there is "stuff" that's generated, that's why I asked if these are clean numbers or if remaining garbage from the actual processing is still contained in that number.
If that's the actual number of bytes claimed, then I still don't get it: Assuming 2Kb per HTML file on average(!) (which is still much more than I would expect - I have 1 kb on average) then each single byte from those files (spaces, angular brackets, text characters, etc.) will generate 1000 bytes of transformed / generated content. I just cannot believe that's the case.
@Tragetaschen the numbers I got were just looking at the task manager and keeping track of what the maximum used memory was. I'm not sure why you are focusing on the HTML templates though. ngc does more than just compile templates.
@mattem if you're already reaching 1.54GB without Uglify/ModuleConcaternationPlugin, then it looks like your project as is needs more than the default node max memory. At how much memory does your project peak when doing just ng build?
@mattem can you open an issue called "Total rebuild test time in medium and large projects", similar to the one I asked @tolitech to open in #5618 (comment)? It's a broader topic as well.
@Tragetaschen I measured tsc peak as well and it's 830MB. Bear in mind however that ngc both compiles templates, transforms code, and generate new TS files. So total TS files processed would be around double. I pinged the team about the difference between ngc and tsc.
We don't run into memory issues (yet, I guess) when running development builds, we are generally experiencing the same as what @tolitech has already mentioned. (I'm keeping an keen eye on the progress of the Bazel building and the work being done there, happy to be a guinea pig for any of that)
@filipesilva Just to be sure: It's not that I care about the HTML compilation step per se, it's that you claimed 3.3 GiB memory consumption just for HTML and NgModule processing "reasonable for project size". Using a thousand times the memory compared to the input data size while the resulting bundle (even without any further optimizations) is over an order of magnitude smaller just isn't reasonable.
Sure, there are bigger problems when it comes to memory consumption right now and I wish I could me more (well, any kind of) constructive, but the entire compilation process currently takes one or two orders of magnitude (!) more memory than I would call "reasonable".
@Tragetaschen I think Felipe is commenting on your math. That step doesn't just involve the HTML file but includes the typescript and CSS files too. In order to properly uglify your entire project is brought into memory, so you can't just count the HTML. Additionally, some of your logic may cause duplication of subsets of your Dom, exploding the size. This is a complicated task that will take a good amount of RAM. We should use as little as possible, but we can't expect miracles.
We're updating the Webpack version used in the CLI in #8689 to include the fix for excessive memory usage in ModuleConcatenationPlugin (webpack/webpack#5997).
This will be available in the next release of Angular CLI and should address most of the reports of excessive memory usage in 1.3.x and up.
I'd like to reiterate that it is expected that projects will reach the memory limit after a certain size. The bigger your project is, the more memory it will need to be built especially in --prod.
For those cases the recommendation is that you run the CLI with an increased memory limit via a npm script:
Then you can do npm run ng-high-mem -- build --prod to do a production build. Note the double dash (--), it is used in npm scripts to separate args.
In this script the limit is increased to 8gigs. You can use a bigger number if you need.
Meanwhile we will keep on making improvements to reduce the memory footprint of the Angular CLI build system.
@changLiuUNSW I've opened a separate issue to track the excessive build time increase when using --build-optimizer: angular/devkit#305.
Reacted by Ashish Mulaye, Etienne Talbot, bertrandg, Lucas Basquerotto, David Neukirchen, Adam Wamai Egesa, Emanuel Victor de Oliveira Fonseca, Brett Larson, Nehal Damania, kxhira and 4 more
Reacted by Ashish Mulaye, Jason D. Hobbs, Balázs Rostás, Adam Wamai Egesa, Evan Koehler and Emanuel Victor de Oliveira Fonseca
Reacted by Etienne Talbot, Adam Wamai Egesa, Emanuel Victor de Oliveira Fonseca, Nehal Damania, Lennart Hoffmann, Ricardo Varanda, GARCIA Guillaume and Marçal
I usually run the build process, and then just look at the task manager to see how much memory the process is using. Peak memory usage is just the biggest number I saw for memory usage while the process was running.
Thanks @filipesilva for your post above re: "ng-high-mem". I confirmed with my project that this does work and I no longer run out of memory during prod build with aot and build-optimizer on. Without this I ran out of memory.
package.json scripts:
"ng-high-mem": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng"
Now this works:
npm run ng-high-mem -- build --prod --aot=true --build-optimizer=true
Note in your msg above you wrote:
"Then you can do npm run ng-high-mem -- --prod to do a production build."
But I think you missed "build" in there:
npm run ng-high-mem -- build --prod
@dobrinsky have you tried running your webpack config with node --max_old_space_size=8192 to increase the memory limit? What is the maximum you see then? If it's just above the maximum you saw before it might just be that you need that little extra bit of memory.
@Jayaraj8905 at this point your best bet is to either use that script (ng-high-mem) or update. 1.2.0 was a long time ago and we don't publish fixes for it anymore.
Using ng-high-mem option with @angular/cli 1.5.4 solved it for me.
Using @angular/cli 1.5.5, I saw 30-40% less memory usage, but still memory outage, so still ng-high-mem required for my build.
Now using ng-high-mem (with 8192) it is using a lot more memory. Is it using more when it has more memory available?
Hopefully that will also speed up the production build a lot. I just migrated from the old Angular 2 way (ngc aot + rollup) to angular/cli and the build time grow from 4m to about 12m. :-(
@filipesilva I saw a new version of webpack has been release days ago which ships your performance tuning code, when will angular-cli release a new version refer to the latest version of webpack? Thank you.
Increasing --max_old_space_size works for me, but after an hour or so, my RAM (32Gb) usage hits 70% or 80%, incremental builds slow down, and node or ng serve crashes.
Is there any ETA on release with aforementioned deps update? Fighting with this issue in our CI which doesn't have much RAM for now, so this fix is urgently required (I know I can hack package.json to point directly at master, but this is a hack I want to avoid).
@krassx try this for production u can just use prod node --max_old_space_size=4096 --stack_size=512 ./node_modules/@angular/cli/bin/ng build --prod -vc --build-optimizer=false
refer to this page for more option https://github.com/angular/angular-cli/wiki/build
@filipesilva I am sorry , I am traveling and missed your question to me. To reply, yes, my problems started after updating to 1.5.0 and plain ng build --prod failed with any 1.5.x. I had to build, as many others, with raised memory node --max-old-space-size=8192 node_modules\@angular\cli\bin\ng build --prod.
Having said that at the same time as I updated to 1.5 I included 3rd party library that probably sent the build process over the edge.
And now the good news. I have just updated to 1.6 and the build finishes just fine with plain old ng build --prod.
I upgraded to cli 1.6 and angular 5.1.
The max memory the production build now using is around 1.3 GB. So no heap errors anymore.
Strange thing is that the process is 'hanging' at '92% chunk asset optimization' for 7 minutes of the total of 9 minutes buildtime.
What is happening there?
Reacted by Francesco Borzì, Daniel Zolnjan, Willian Oliveira, Balázs Rostás, Zdeněk Haták, Jorge V, Dries De Smet, David Stapp, Brenden Niedermeyer, Developer Thing and 14 more
We still have this issue. We had this issue since angular@2 when I first time used angular CLI. Then I switched to angular starter and everything worked. Now Im trying to use angular cli again on the same project (upgrade from angular 4) and now I still have same issue with angular 5.1 and cli 1.6.2.
We have a really huge project and we are using angular on this project from early versions of angular since 2013.
When I simply use ng build build is going 1 hour. Here is a log.
When I use ng build I always have an error (after few minutes of build):
ng build
10% building modules 3/3 modules 0 active
<--- Last few GCs --->
[30628:0x102804600] 151498 ms: Mark-sweep 1405.8 (1664.5) -> 1405.8 (1664.5) MB, 1634.9 / 0.0 ms allocation failure GC in old space requested
[30628:0x102804600] 152767 ms: Mark-sweep 1405.8 (1664.5) -> 1405.7 (1616.5) MB, 1268.5 / 0.0 ms last resort
[30628:0x102804600] 154066 ms: Mark-sweep 1405.7 (1616.5) -> 1405.7 (1601.0) MB, 1298.4 / 0.0 ms last resort
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x14c9d8b1cef1 <JSObject>
1: set [native collection.js:~247] [pc=0x2fa4affd9607](this=0x166929284d21 <Map map = 0x20d66a1183b9>,p=0xb60e511a3c9 <NodeObject map = 0x78bae661b01>,x=0x3ce8d86d6ce9 <Object map = 0x3647e82a689>)
3: record [/Users/pleerock/www/yakdu/ng5.yakdu.dev/node_modules/@angular/compiler-cli/src/transformers/node_emitter.js:135] [bytecode=0x214b10b7f429 offset=37](this=0x166929284ce9 <_NodeEmitte...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [/usr/local/bin/node]
2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
4: v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
5: v8::internal::OrderedHashTable<v8::internal::OrderedHashMap, 2>::Rehash(v8::internal::Handle<v8::internal::OrderedHashMap>, int) [/usr/local/bin/node]
6: v8::internal::Runtime_MapGrow(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
7: 0x2fa4afe040dd
Abort trap: 6
If you want to know how many code and files we have:
@pleerock have you tried using the command to increase max memory, on both prod and dev builds?
If your project is near to the maximum memory it will need a lot of GC and that slows down things. Increasing the max memory even when you're not hitting it (like in dev) should help.
@filipesilva thanks, it works. Both prod and dev builds. And build time is still 1 hour. Im glad that it works this way, however having to wait 1 hour each time is a problem. Also, its a big problem to run ng serve. When we run it, it takes same 1 hour to start serving which makes development process completely impossible.
@pleerock yeah 1h for ng serve is really odd. I have never seen such a large build time in any projects I've handled.
I have reports of slow prod builds of that length (#6795) but haven't heard of anything like that just for ng serve... I use https://github.com/filipesilva/angular-cli-test-repo as a benchmark for larger projects and it has around 2400 TS files, but still only takes a few minutes.
Is your repro public or is there a way that I can see it?
Another option would be to take a CPU profile (there's some instructions here #8259). But I wouldn't be surprised if the devtools crash, they usually do on huge jobs. Maybe a CPU profile of just a few minutes would be feasible?
Activity
JonathanYates commentedon Nov 14, 2017
@jmcclanahan @filipesilva
ng serve : SUCCESS
ng build : SUCCESS
ng build --prod : FAIL
ng build --prod --build-optimizer=false : FAIL
ng build --aot : FAIL
ng build --aot --build-optimizer : FAIL
output as per #5618 (comment)
It also takes several 'minutes' hung at 92% before producing an error.
How do you suggest I produce a production build?
seanlandsman commentedon Nov 14, 2017
Hi @filipesilva
What version of the CLI and Angular are you on?
1.5
Does this only happen on ng build --prod?
No, with --aot and --build-optimizer it fails too (see below)
Do you still get the memory error with these build commands:
For the commands that fail, it can be intermittent - ie. fail 4/5 times, but pass on the 5th
ng build --build-optimizer=false: Passes
ng build --aot: Passes
ng build --aot --build-optimizer: Fails
I can get these to pass 100% of the time by increasing the amount of available memory (ie: node --stack_size=4048 node_modules/.bin/ng build --prod | OR by --build-optimizer=false)
I've created a simple repo of the problem here: https://github.com/seanlandsman/build-optimiser-issue
Steps to reproduce:
npm install
npm run prod (note: this fails most of the time, but very occasionally it will pass)
thanks
JonathanYates commentedon Nov 14, 2017
I don't think increasing the node --stack_size is a good idea. All that will do is mask the real issue here. The build should not be gobbling up so much memory. There is a fundamental problem that needs to be fixed.
MichalEmbiq commentedon Nov 14, 2017
Think about CI, some environments don't have so much memory. How this "feature" pass tests? Why issue is closed?
joecot commentedon Nov 14, 2017
If folks want to complain about memory requirements, they can. If folks want to say it's unreasonable this bug exists, they can. If folks want to encourage people to no longer use Angular, they can. The developers are already looking at this, no amount of vitriol will make that faster. In the mean time, add a swap volume, increase the stack size, and subscribe to the issue for updates -- which unfortunately will likely be mostly complaints for a while.
josephliccini commentedon Nov 14, 2017
Not sure if this is just my experience or not, but in cases where I had template errors (used a non-public variable in template, used the wrong type for an
@Input(), etc.) I would see the memory usage climb really high, and then crash the build. My suggestion is to make extra sure that there are no template errors. This can be done by invokingngcdirectly on the project. Not sure if that will help, just sharing my experience.filipesilva commentedon Nov 14, 2017
Hey all,
I've been running a bunch of memory profiles on projects to try and figure out what the cause is. I'm comparing projects using CLI 1.5.0 + Angular 5.0.0 + Typescript 2.4.2 against CLI 1.4.9 + Angular 4.4.6 + Typescript 2.3.2. Special thanks to everyone that provided repros, that helps a lot.
@magemello I'm having some trouble building your project. It seems to be a couple of missing style variables (like
$alfresco-typography). I assume I have to build these before the app. Can you tell me what the missing steps are? This is what I did:@seanlandsman I could not reproduce with the repository you linked. I got the same results with 1.4.9 as I did with 1.5.0. Builds seemed to finish in roughly the same amount of time, and consume a maximum of 500 MB of memory. Bundle sizes were also the same (more on that in a second). Can you think of anything I might be missing? I'm on Windows 10, node 8.9.1.
@teabagp using your repro (#8457 (comment)) I saw both a bundle size increase (500kB to 4MB) in 1.5.0 and a memory usage increase (from 580 to 1080 MB). This is the only community repro I really have at the moment, if someone else has a project I can look at please let me know.
The last repro is specially relevant because it shows this problem even in a small project. Those of you that ran into memory problems that went away after increasing the memory limit, can you tell me if your bundles also got significantly bigger?
Based on @teabagp's repro, this is what I can currently say:
devextremeanddevextreme-angular),10% building modulesphase and memory usage seems normal then.At the moment I don't think the 1.5 memory usage increase is directly related to either Build Optimizer or Sourcemaps. Both of these increase memory usage by virtue of doing more thing. So bigger projects should indeed use more memory. We should still keep this under control but for the 1.5 specific problem it doesn't seem to be the root cause.
hanvyj commentedon Nov 14, 2017
@filipesilva
Yes, main bundle increased by roughly 4MB. Sadly the project isn't open source, but it's pretty complex anyway the other project is a better example to try diagnose I think.
magemello commentedon Nov 14, 2017
Hi @filipesilva,
sorry for not providing you more information on how to run it correctly:
filipesilva commentedon Nov 14, 2017
@magemello I'm on windows and unfortunately that script doesn't seem to be very windows friendly even with gitbash...
Is there something I can do even if hacky to get around the need for it? Ideally without removing the global styles as I'm also investigating if style processing is using a lot of memory.
filipesilva commentedon Nov 14, 2017
@hanvyj thanks for confirming that!
randyaa commentedon Nov 14, 2017
@filipesilva
We started experiencing this pretty significantly in CLI 1.3 & it got worse with 1.4 and so we downgraded to 1.2.6 and haven't had any problems since. we're still running ng 4.4.6 with cli 1.2.6 and it seems fine with default settings.
I don't have a ton of time to dig into this right now so i'm sorry this won't be super helpful but just wanted to let you know where the version numbers went wrong.
We are locked into the following specific versions (along with material
2.0.0-beta.12). if we change JUST cli to 1.3 or 1.4 (and presumably 1.5) we see the issue:We were hoping to upgrade soon so glad to see some focus on the issue. Thanks so much!
magemello commentedon Nov 14, 2017
I have executed it for you:
seanlandsman commentedon Nov 14, 2017
@filipesilva
I've just tried on a clean install and it still fails for me. I'm on OSX Sierra and am running node v7.7.3
I also note that if I run ng build --prod --build-optimizer=false it will run successfully repeatedly, whereas running just ng build --prod will fail most of the time.
I'm not sure what I can add here - is there some sort of profiling I can run on my side and provide the output?
thanks
rajravat commentedon Nov 14, 2017
this is also affecting me, using angular 5 and cli 1.5, ive had to switch off the build optimizer to get my builds to pass without a out of memory error :(
filipesilva commentedon Nov 14, 2017
@seanlandsman do the bundle sizes remain the same?
seanlandsman commentedon Nov 14, 2017
@filipesilva
With "node --stack_size=4048 node_modules/.bin/ng build --prod" I get:
1.4K 14 Nov 20:43 inline.aa760cefdeaeea9e038f.bundle.js
835K 14 Nov 20:43 main.05e5301d42766024fc03.bundle.js
60K 14 Nov 20:43 polyfills.e6475d2787bb3154d59c.bundle.js
48K 14 Nov 20:43 styles.9b2fb464224d0a79781d.bundle.css
With "./node_modules/.bin/ng build --prod --build-optimizer=false" I get:
1.4K 14 Nov 20:45 inline.d7125ae6ed51e3e3af81.bundle.js
4.9K 14 Nov 20:45 main.47d0056e07ee5cb9c483.bundle.js
60K 14 Nov 20:45 polyfills.ad37cd45a71cb38eee76.bundle.js
48K 14 Nov 20:45 styles.9b2fb464224d0a79781d.bundle.css
951K 14 Nov 20:45 vendor.799da157f41ee457e4bd.bundle.js
Interestingly you can see the main.xx.js got much bigger with in the first run, but the vendor file disappeared. This might be expected?
One further bit of information - I just tried this on an older Mac running El Capitan (node version v7.7.3) that I've not used for a while. When I run "node_modules/.bin/ng build --prod" it runs just fine, repeatedly, and much faster than on my current machine. Hopefully this is helpful.
thanks
Dunos commentedon Nov 14, 2017
@filipesilva our build also got increased by 3MB or 4MB like the last example you said, taking a long time after the 92%, and we also use the devextreme libraries. Can't share the project repo unfortunately but I could provide our package.json if neeeded.
dzonatan commentedon Nov 14, 2017
@filipesilva try to reduce the
stack_sizeto reproduce the @seanlandsman case.node --stack_size=512 node_modules/.bin/ng build --prodgets me that error on my mac.tim-white87 commentedon Nov 14, 2017
@filipesilva
What version of the CLI and Angular are you on?
1.5 and 5.0.0 respectivley
Does this only happen on ng build --prod?
Only when the --aot flag is use.
Do you still get the memory error with these build commands:
ng build --build-optimizer=false
no
ng build --aot
yes
ng build --aot --build-optimizer
yes
If you have a project that I can look at, can you link it please?
Sorry, but our application is private per our corporate requirements.
alvachien commentedon Nov 15, 2017
@jmcclanahan @filipesilva
ng serve : SUCCESS
ng build : SUCCESS
ng build --prod : FAIL
ng build --prod --build-optimizer=false : FAIL
ng build --aot : FAIL
ng build --aot --build-optimizer : FAIL
output as per #5618 (comment)
It also takes several 'minutes' hung at 92% before producing an error.
Is there any workaround to bypass it?
It is not working with the --max_old_space_size=8192
JackArlington commentedon Nov 15, 2017
I have the same problem. I also recognized that the size of my application with ng serve drastically increased after the update to angular 5. With angular 4 the vendor.bundle.js created by ng serve used to be 10MB and with angular 5 it is now 30MB.
ng serve -> works
ng build -> works
ng build --prod -> fails
ng build --prod --build-optimizer=false -> fails
ng build --aot -> fails
ng build --aot --build-optimizer=false -> fails
magemello commentedon Nov 15, 2017
@filipesilva we all could also help debugging the webpack build, what tool are you using to debug it?
I was trying like that, but I'm not sure is the best way:
node-nightly --inspect-brk ./node_modules/@angular/cli/bin/ng build --prodIf you give me more instructions here or on Gitter I will be more than happy to help.
filipesilva commentedon Nov 15, 2017
Heya, using the repros you all provided I believe I've found the main problem with 1.5. It has to do with how the new pipeline moved decorator removal into Build Optimizer.
For those interested in a more detailed explanation, this is what happens:
--aot, we use TypeScript transforms in Build Optimizer to remove Angular decorators (stuff like@Componentand@NgModule) from both your app and libraries (they aren't needed after AOT).ng build --aotwhen using CLI1.4.9+NG4 versus CLI1.5.0+NG5.devextremelib case, there was almost 9megs of extra code included.There might be more factors contributing to the excessive memory usage but currently this is the approach I'm following as it's the most promising one. I hope to have a PR with a fix soon.
radoslavpetranov commentedon Nov 15, 2017
@filipesilva awesome news! Thanks for sharing your progress - very much appreciated!
Some of us are experiencing this in non-latest-version setups and others all the way back in cli 1.2 and 1.3 setups. Do you believe this is just a natural limitation and expected behavior due to the size of the projects/dependencies? Is the default <2GB RAM allocation just naturally too small for compiling bigger projects?
filipesilva commentedon Nov 15, 2017
@radoslavpetranov I have been thinking about that (@randyaa said the same thing as you), and trying to figure out what a good approach is.
Something that springs to mind is to split up into multiple processes. But upon further scrutiny that approach doesn't really help in the memory usage problem, since multiple process will use at least the same total memory, probably more due to inefficiencies and duplication.
The 1.5 problem highlighted how much Build Optimizer actually helps keep memory usage down by trimming imports (and thus project size). So maybe that's an overall better approach. It does imply that a project must be able to use Build Optimizer though, and there might still be problems with it (code manipulation is tricky).
Another approach might be to took a look at the Uglify memory usage in large bundles. Maybe there room for config tuning or something. But it's hard to say since those tools really rely on a semantic understanding of code bundles to work, so one does expect a lot of memory used on larger bundles.
Something else that I've been thinking about is to actually have a low memory setting, where disk/cpu/total time is traded for a smaller memory footprint. This is just a very high level idea that I haven't explored at all. It would help on limited environments like CI, whereas for dev environments you really want the tradeoffs that give you better rebuild/speeds instead.
For really large projects you just can't get around the fact there are more performant languages than JS and that build tools that can use them effectively (like Bazel) will offer a better experience.
erlloyd commentedon Nov 15, 2017
@filipesilva - Thanks for investigating this. Here's another data point, fwiw:
What version of the CLI and Angular are you on?1.5.0 and 5.0.0
Does this only happen on ng build --prod?Seems to be building fine without the --prod flag
Do you still get the memory error with these build commands:ng build --build-optimizer=falseno
ng build --aotno
ng build --aot --build-optimizerno
If you have a project that I can look at, can you link it please?Sorry, private repository and project
mattem commentedon Nov 15, 2017
@filipesilva Thanks for the update and explanation, however we experience this with our projects using cli 1.4.7 and angular 4.4.5 (and early versions too). Currently to build our production version we use the following:
ng build --environment=prod --aot --sourcemaps=false --base-href=\"/ui/\" --preserve-symlinks --output-hashing=all --extract-css=trueWe then pass the output to Uglify to minify and mangle the JS and CSS. This process works correctly and we do not hit memory issues, but when we build with
ng build --prodthat is when we run into memory issues.We also do not have the
devextremelib. I can't share our code, but I'm happy to install other versions of the CLI and post build results from different commands. Our application is approx 450 components and 290 modules.eduardotolino commentedon Nov 15, 2017
Hello @filipesilva
I don't know exactly if this my comment might be useful, but I will report some tests that I did.
I have an angular-cli (1.4.1), angular (4.4.4), typescript (2.3.4) project.
This project contains approximately 200 services and more than 700 components, distributed in at least 15 modules.
When running
ng build --prodI noticed a few things.In this specific project, 0 to 1.9 GB of memory occurs up to the first 10% of the compilation.
(I'm using the saas files from bootstrap).
From the 11% up to the 89% compilation, my memory goes up to less than 3 GB.
From 90% to 92% the memory is used in 4.6 GB.
And finally at 95% the consumption goes up to the maximum limit allowed.
In my case now, up to the 6 GB of RAM I've bound.
To make it compile, I had to configure virtual memory (swap).
I have only 8 GB RAM.
I increased to 12 GB, 16 GB, until finally I was able to compile the project by setting 32 GB RAM.
Consumption of NodeJS hit 28 GB at these same 95% emitting.
Unfortunately this project is private and would not be able to make it available.
Tests requested:
ng build --build-optimizer=falseworks! 1.5 GB max.ng build --aoterror!To try to help, I created a very simple project.
In it, there are 10 modules created.
In each module, there are 50 components created.
In each component there is only one HTML with output "works!".
There is no CSS, there is no third-party npm component.
A simple project like this is consuming 1.6 GB of RAM for the AOT build.
I believe that consumption is a little high because it contains absolutely nothing in the project.
If you wanted to download the repository to test, it is zipped in the link below.
http://www.codegenerator.com.br/downloads/ng-heap-memory.zip
Thanks in advance for your help.
fix(@ngtools/webpack): remove app decorators on AOT
fix(@ngtools/webpack): remove app decorators on AOT
filipesilva commentedon Nov 15, 2017
I've put up a PR that should specifically address the memory usage regression when using 1.5 (#8506). Once it's merged and released I'll ping you all here to see if it helped across your projects.
@tolitech your report of how memory usage changed with build stage was very interesting and useful. Below the 92% stage what happens is TypeScript compilation and loading files into Webpack. After that it's mostly Uglify and Build-Optimizer.
But since you are on
1.4.1you shouldn't have Build Optimizer by default with--prod. Just to double check, can you confirm that you are not using--build-optimizer?In your report you mention using what I consider a large project (200 services and 700 components). Definitely not the largest around but still big. I'm not surprised at a 3GB memory usage for TS compilation and loading all app files.
But when it starts getting really bad is after that, when you end up needing at least 28GB at the 92% phase. This to me tells me the bottleneck is Uglify, or maybe some other part of our build pipeline that I'm not seeing right now. But it definitely bears investigating, which I'll do.
Running the small
ng-heap-memoryproject as is I saw a maximum of 1.4GB ram being used. Using the PR this dropped to around 800MB, so it seems to be helping there. I agree that the 500 components are essentially empty, but it doesn't surprise me that just the sheer number of them causes high memory consumption on a build. It's a valuable example by the way, and thank you for making it.@mattem that's a very interesting approach, and doubly interesting is that you don't suffer much memory issues with it. Can I ask you to give me some concrete numbers for comparison please? Maximum memory usage on a CLI prod build versus CLI non-prod plus manual Uglify. I'd also like to know your uglify version and settings please.
eduardotolino commentedon Nov 15, 2017
Hello, @filipesilva
Yes, I confirm that I'm using without
--build-optimizer.Just
ng build --prod.And thanks for the feedback.
WandererInVoids commentedon Nov 15, 2017
@filipesilva i used same workaround i described it in my comment #5618 (comment)
command
ng build --app homeapp -aot=true -e=prod -sm=false -ec=true --named-chunks=false -oh=all --build-optimizer=true -vc=truemy memory usage:
0 % -18 % <= 828 mb
18% -89 <= 1140 mb
90 - 100 < 1253 mb
difference between --build-optimizer=true and false 90 mb
for uglify used gulp-uglify^3.0.0 default settings 1058 mb
also i used gulp-postcss for uglify and autoprefixer all latest version
@angular 5.0.1
@angular/cli 1.5.0
mattem commentedon Nov 16, 2017
@filipesilva Using
ng build --prodgave the OOM error, however running the CLI withnode --max_old_space_size=8192it did complete, with the following memory usage (observed from looking at Activity Monitor in MacOS):Running with
ng build --environment=prod --aot --sourcemaps=false --base-href="/ui/" --preserve-symlinks --output-hashing=all --extract-css=true(no increasingmax_old_space) tops out at 1.49gb real / 6.23gb virtual. This is running with@angular/cli@1.4.7and@angular/*@4.4.5We use
gulp-uglify@3.0.0, giving usuglify-js@3.0.28, setting compress and mangle totrue.The output is also run though
loose-envify,uglifycss, andhtmlminThe gulp task peaks at 868mb real / 5.57gb virtual.
fix(@ngtools/webpack): remove app decorators on AOT
fix(@ngtools/webpack): remove app decorators on AOT
PeS82 commentedon Nov 17, 2017
According to changelog the above mentioned fix is included in 1.5.1+. It still fails for
ng build --prodwith 1.5.2 :(95% emitting
<--- Last few GCs --->
[4980:000001B75DBAB8D0] 268298 ms: Mark-sweep 1399.5 (1698.5) -> 1399.5 (1698.5) MB, 483.4 / 0.0 ms allocation failure GC in old space requested
[4980:000001B75DBAB8D0] 268868 ms: Mark-sweep 1399.5 (1698.5) -> 1399.5 (1629.5) MB, 569.7 / 0.0 ms last resort GC in old space requested
[4980:000001B75DBAB8D0] 269387 ms: Mark-sweep 1399.5 (1629.5) -> 1399.5 (1600.0) MB, 518.8 / 0.0 ms last resort GC in old space requested
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 00000185B7C25EC1
1: DoJoin(aka DoJoin) [native array.js:~95] [pc=0000002F55357679](this=00000075A3182311 ,p=0000001FB1A5B831 <JSArray[937]>,q=937,E=00000075A31823B1 ,A=00000185B7C6EC69 <String[1]: >,z=00000075A3182421 )
2: Join(aka Join) [native array.js:~120] [pc=0000002F550C6489](this=00000075A3182311 ,p=0000001FB1A5B831 <JSArray[937]>,q=937,A=00000185B7C6EC69 <Str...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
jayhamilton commentedon Nov 17, 2017
Still encountering this issue with angular cli 1.5.2
`ng build --aot --prod
95% emitting
<--- Last few GCs --->
209426 ms: Mark-sweep 1512.7 (1406.8) -> 1512.5 (1406.8) MB, 453.1 / 0.0 ms [allocation failure] [GC in old space requested].
209905 ms: Mark-sweep 1512.5 (1406.8) -> 1513.6 (1403.8) MB, 479.5 / 0.0 ms [last resort gc].
210359 ms: Mark-sweep 1513.6 (1403.8) -> 1514.7 (1403.8) MB, 453.6 / 0.0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x4353ac3fa99
1: SparseJoinWithSeparatorJS(aka SparseJoinWithSeparatorJS) [native array.js:~75] [pc=0x1e05abc97c4a] (this=0x4353ac04241 ,w=0x1a58c504381 <JS Array[1078]>,F=0x1a58c5043a1 <JS Array[1078]>,x=1078,I=0x37d7075bc209 <JS Function ConvertToString (SharedFunctionInfo 0x4353ac5dbc9)>,J=0x4353ac4a369 <String[1]: >)
2: DoJoin(aka DoJoin) [native array.js:~129] [pc=0x1e05abb3c1b6] (thi...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [/usr/local/bin/node]
2: node::FatalException(v8::Isolate*, v8::Localv8::Value, v8::Localv8::Message) [/usr/local/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
4: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
5: v8::internal::Runtime_SparseJoinWithSeparator(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
6: 0x1e0596e060c7
Abort trap: 6
Jays-MacBook-Pro:ngx-dynamic-dashboard-framework jayhamilton$ ng --version
/ \ _ __ __ _ _ | | __ _ _ __ / | | | |
/ △ \ | ' \ / _
| | | | |/ _| '| | | | | | |/ ___ | | | | (| | || | | (| | | | || | | |
// __| ||_, |_,||_,|| _|||
|___/
Angular CLI: 1.5.2
Node: 6.11.1
OS: darwin x64
Angular: 5.0.1
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic, router
@angular/cdk: 2.0.0-beta.12
@angular/cli: 1.5.2
@angular/material: 2.0.0-beta.12
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.36
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.2
@schematics/angular: 0.1.5
typescript: 2.6.1
webpack: 3.8.1
`
finalxcode commentedon Nov 17, 2017
@jayhamilton +1 swimlane/ngx-datatable#1104 (comment)
filipesilva commentedon Nov 17, 2017
Hey all,
1.5.2includes the fix for the 1.5 memory usage regression. This should help users that had projects that did not have memory problems on 1.4 but started having them in 1.5.Projects that were already having memory problems in 1.4 should see no change. I'm still looking into the balooning memory requirements for the
92% bundle optimizingphase.@PeS82 @jayhamilton @finalxcode you reported that you're still running into memory problems with
1.5.2. Was this on projects that did not have memory problems in1.4.x?finalxcode commentedon Nov 17, 2017
@filipesilva With angular cli 1.4.x it used to work, then when i upgrade angular/cli to 1.5.2, it have memory problems, i have to use command
node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod --aotto buildJackArlington commentedon Nov 17, 2017
@filipesilva with cli 1.5.2 my project fails at 95%. With angular cli 1.4.x it used to work.
Shadowlauch commentedon Nov 17, 2017
@filipesilva @JackArlington same for me. Our project used to build (prod) on 1.4.x and since 1.5.0 does not anymore. 1.5.2 didnot improve the situation. When I increase the memory limit it does compile, but uses aprox 5GB on emitting.
On a side not the huge memory consuption occurs on "95% emitting"
JackArlington commentedon Nov 17, 2017
@filipesilva @Shadowlauch I have just recognized that the machine I tested before had node 6.x upgrading it to 8.9.1 solved the problem and ng build --prod --aot works now.
Thank you for the help.
filipesilva commentedon Nov 17, 2017
To be clear, I am not aware of any memory issue related specifically to Node 6. I have been testing with Node 8.9.1 myself because I couldn't get memory timelines using Chrome Devtools with Node 6.
Maybe that's part of the equation here... I expect newer nodes to be faster and more memory efficient but perhaps there's more to it.
For instance, I couldn't repro the problem on @seanlandsman's project. @seanlandsman what version of node were you using?
Shadowlauch commentedon Nov 17, 2017
I had node 6.x aswell and after upgrading to 8.9.1 it works now. @JackArlington thanks for the tip!
seanlandsman commentedon Nov 17, 2017
@filipesilva I'm on node 7.7.3
Edit: I've just upgrade the test repo to 1.5.2 and retried - it still fails I'm afraid.
Did you try running with "node --stack_size=512 node_modules/.bin/ng build --prod" to see if this helps reproduce what I'm seeing?
thanks again
changLiuUNSW commentedon Nov 17, 2017
@filipesilva
I do not get
heap out of memoryerror anymore withcli 1.5.2. My node version is7.5.0.However the build still takes about
8 - 10 minutesto finish.magemello commentedon Nov 17, 2017
@filipesilva I have updated the version and I'm still having the same problem :(
Here are the versions which I'm using:
If you give me enough instruction on how you debug the webpack build I can help find the source of the problem....
jinder commentedon Nov 17, 2017
Can confirm that it's fixed the problem for us. Using 1.5.2 and Node 9.2.0 - no longer need to increase Node memory.
Dunos commentedon Nov 17, 2017
With the new 1.5.2 release, my memory problem and bundle size haven been fixed, it still takes some time stuck at the 92% but works in the end.
filipesilva commentedon Nov 17, 2017
@seanlandsman I tested your repros again with
--stack_size=512and--stack-size=8048and only saw memory consumption in the 400-500MB range. The default seems to be--stack_size=984btw.I did see something else though:
This seems consistent with what
--stack-sizeactually does (nodejs/node#6360). It doesn't increase total available memory, but rather the the size of each stack region that node uses. It that increasing it can solve issues with a lot of recursion (but that code should try to not have that).The symptoms seem to be different on OSX (memory bust) and Windows (maximum call stack size exceeded). I don't know why that is.
I think the problem you're experiencing is solely related to Build Optimizer as you posited, and is the one tracked in angular/devkit#240. Still relevant for this thread mind you, but the specific issue is that one.
@changLiuUNSW were your build times with 1.4.x shorter, and if so, by how much?
@magemello I'll ping you on the gitter you provided and see what we can do in your project.
changLiuUNSW commentedon Nov 17, 2017
@filipesilva
I do not have a chance to try 1.4.x because we used CLI 1.3.0 in our project before
Angular CLI 1.3.0 with Angular 4.2.4
Angular CLI 1.5.2 with Angular 5.0.1
I understand in 1.5,
--build-optimizeis enable by default for production build, but 5 minutes difference between 1.5 and 1.3 is not good.filipesilva commentedon Nov 17, 2017
@changLiuUNSW I agree 5 minutes difference is a long time. Can you try
--build-optimizer=falsefor now please?changLiuUNSW commentedon Nov 17, 2017
@filipesilva
Angular CLI 1.5.2 with Angular 5.0.1
6 minutes difference with
build-optimizer=truemagemello commentedon Nov 17, 2017
Thank you @filipesilva for your help, I did the following:
and now the result is the following:
So, in general raise the max_old_space_size fix my issue at exception of the "ng build --prod", in this case my problem seems to be related to this: angular/angular#20115.
In other words the problem seems to be the presence of ts files in my libraries and aot geting angry about it :), the solution for this point seems to be put ts file in the .npmignore and exclude it from the packages. (haven't test it yet)
I'm just reporting the finding, hopying it helps others....all the credit goes to @filipesilva.
filipesilva commentedon Nov 17, 2017
@changLiuUNSW @tolitech can I ask you to do some more advanced debugging if you have time? I don't have access to your projects but they seem good examples.
@changLiuUNSW Your project doesn't seem to have memory problems anymore but it is taking very long to build with Build Optimizer.
I think one of the build optimizer transformations is taking a very long time on your codebase, but I can't know which ones. I can tell you how to disable each one individually though.
You can do this in
./node_modules/@angular-devkit/build-optimizer/src/build-optimizer/build-optimizer.js. From line 63 to line 82, each transform is individually added to thegetTransformsarray. You can comment out each of thegetTransforms.push(and that transform will not be added.If you can do this for each one and time me how it impacts build time, I might be able to figure out which of the transforms is taking too long.
@tolitech your project has problems with memory usage with 1.4.x, and you have already confirmed it does not use build optimizer. You reported that memory usage went up to 28gigs during a prod build.
I'd like to ask you to do a couple of things. First, can you tell me the memory usage of just
ng buildplease?Then, I'd like you to try to manually disable Uglify. This can be done in
./node_modules/@angular/cli/models/webpack-configs/production.js, line 111-117 (thenew webpack.optimize.UglifyJsPlugin({call). Comment those lines, and try to do a production build again (with increased memory limits). What was the maximum memory used?I understand that debugging these things take time and appreciate that you take the time to do it. I'm doing the same things on projects I have access to but each project is different so it's very difficult to zone in on the exact issue without having access to the code. Asking you to do some tests is the next best thing.
radoslavpetranov commentedon Nov 17, 2017
Running
ng build --aot --prodyielded the followingtook nearly 10 minutes but the build did complete and didn't exceed the 1.3GB RAM mark now. By the looks of it, the bundle also decreased in size. Before I was getting a main bundle of 1.98 MB and a vendor bundle of 1.51 MB and now I only seem to have a single main bundle of 2.49MB.
The dev bundle went from vendor 16MB and main 4.61MB to vendor 5.91MB and main 1.87MB and it didn't exceed the 800MB RAM mark.
This was generated with the following setup
I'll update my node to the latest 8.* version and I'll see if this changes anything in terms of RAM consumption.
markmaynard commentedon Nov 17, 2017
@filipesilva I was looking at the package.json for Angular:
"engines": { "node": ">=6.9.5 <7.0.0", "npm": ">=3.10.7 <4.0.0", "yarn": ">=1.0.2 <2.0.0" },I've always taken the engines section to mean that those were the engines supported. Is running Node 8 officially supported or am I reading this all wrong?
radoslavpetranov commentedon Nov 17, 2017
Well, interestingly, node 8.9.1 did complete the bundle nearly twice as fast (~5min 50 seconds) compared to node 6.11 and it did use about ~150-200MB less ram throughout the final (92%-95%) stages of the process.
So although the compilation time reduction was very nice, the node version doesn't seem to play a major role in the RAM consumption issue (at least on my machine/project).
EDIT:
Running
ng build --aot --prod --build-optimizer=falsefinished 3 times faster thanng build --aot --prodbut it did use about 150-200MB more RAM.So all in all build optimizer seems to actually help RAM consumption at the expense of time.
eduardotolino commentedon Nov 18, 2017
Hello @filipesilva
I've done some more tests and would like to share it with you.
To be a fair test, I restarted my laptop at all times when I changed a line in the production.js file and after running ng build -prod.
In all tests, the virtual memory added was 32 GB.
The laptop has 8 GB physical RAM.
In the ng.cmd file the configured command was --max_old_space_size = 32768 in all cases.
It is important to remember that in this test, the total memory allocated is not exactly the total memory required by Node.js, since it would be the total used by the computer in all of its processes.
However, there was no program or process running, and in all tests the computer was restarted.
Let's go to the tests:
Test 1
Configuration:
Total memory allocated by the computer: 36.5 GB
Waiting time to complete: 26 min 24 secs
Test 2
Configuration:
Total memory allocated by the computer: 34 GB
Waiting time to complete: 20 min 52 secs
Test 3
Configuration:
Total memory allocated by the computer: 7.9 GB
Waiting time to complete: 10 min 03 secs
Test 4
Configuration:
Total memory allocated by the computer: 8.8 GB
Waiting time to complete: 13 min 59 secs
Node v8.9.1
Angular CLI 1.4.1
By my tests, I have to conclude that in my specific case, it is the
new webpack.optimize.ModuleConcatenationPlugin()command line that is dramatically increasing my memory need.With this line enabled, my consumption goes from 8.8 GB to 36.5 GB as indicated by the windows task manager.
If you need more tests, just give me instructions.
I work more with .NET, but with instructions I believe I can test.
Thank you.
filipesilva commentedon Nov 18, 2017
@tolitech thanks lot for trying that! I think you're on to something.
The commit that introduced
ModuleConcatenationPluginwas released in1.3.0-rc.0(fe85750).This matches up with what @amikitevich @randyaa and @radoslavpetranov said: their memory problems started with 1.3.0.
Using
ModuleConcatenationPluginis important for two reasons:But it also seems to be causing excessive memory usage in some cases.
I'm a bit at a loss at what I can do about this now.
ModuleConcatenationPluginmight use a lot of memory by design or it might just be a bug, but it's hard to tell without being able to test it myself.To users that started having memory problems after the 1.3x update: can you try doing a build disabling
ModuleConcatenationPluginmanually (same instructions as I gave @tolitech in #5618 (comment)) and tell me if it helps? If it does help and your project is public, can you tell me where I can see it?filipesilva commentedon Nov 18, 2017
@tolitech can you tell me which libraries you use in your app? Maybe I can try including them in a project and can reproduce it like that.
radoslavpetranov commentedon Nov 19, 2017
running
ng build --aot --prodwithnew webpack.optimize.ModuleConcatenationPlugin()commented outrunning
ng build --aot --prodwithnew webpack.optimize.ModuleConcatenationPlugin()activatedNo difference in RAM consumption on my project.
alvachien commentedon Nov 20, 2017
@filipesilva My project is public, and I am facing exactly the same issue after I upgrade Angular-CLI a few days ago. You can have a try on 'ng build -prod' via https://github.com/alvachien/achihui
filipesilva commentedon Nov 20, 2017
@alvachien I tried your project with
1.5.2and itng build --prodbuilt correctly with a peak of 1.2GB memory usage. Did you try1.5.2? There's a fix there that isn't in 1.5.0.@markmaynard what you're looking at is the the
package.jsonfor theangular/angularrepo: https://github.com/angular/angular/blob/master/package.json#L10-L13. That repro is what we call a monorepo, where multiple packages are under the same repository. The engine requirements you see there are for the monorepro itself: the requirements to build the Angular packages. But not the requirements for using the Angular packages. If you check outpackage.jsonfor@angular/core(in yournode_modulesfor instance), there won't be any engine requirements.@mattem @WandererInVoids I tried running a few experiments in a project with a lot of libs, to compare memory usage with and without a separate Uglify process:
ng build --prod: peak 1.1GB memory, 4.1MB main bundleng build --prodwith Uglify manually commented off: peak 0.8GB memory, 10.5MB main bundleCLI used was
1.5.2. It's important to note that I used the same Uglify we use in the CLI (uglify-es@3.1.5, the one included byuglifyjs-webpack-plugin@1.0.0), and that I also used the same flags we use in the CLI:--compress pure_getters,passes=3 --mangle.Flags here are really important because these affect the memory usage and end result. See mishoo/UglifyJS#2113 for some conversation about memory usage in Uglify.
From the numbers I got I wouldn't say there is a problem with how we use Uglify. The difference (1.1GB vs 0.8+0.7) is larger than each process individually but is smaller than both together. I expect this to be because of all the files/sourcemaps loaded into memory.
But it's worth mentioning that by not running
--prodyou are also not runningModuleConcatenationPlugin. Maybe in your projects that's the actual problem and not Uglify. Can you try disabling as well? (see #5618 (comment) on how to disable it).eduardotolino commentedon Nov 20, 2017
Hello @filipesilva
I have tried to create a very similar model of what I use so that the tests can be performed with greater precision.
In this application there are basically 5 main pages (category, status, severity, project and issue) that are replicated 10 times within the same module. We have 50 pages per module. 10 modules totaling 500 pages were created.
For me, a page is composed of 3 components, the entry point, the grid and the form.
So we have 1,500 components created.
There are several other components created and used by the application, base components that are inherited via typescript, pagination, menu, security, shared module, directives, guards, models, resolvers, among other elements.
Not all npm referenced libraries are being used in this example, but I believe the model is quite useful for testing.
In this example, my maximum memory consumption hit 23 GB.
Somewhat below my actual case, because although this example has many more components, the components created in my real case are more complex.
I do not know if I exaggerated the number of elements created for the test.
Although hundreds of services have been created (one for each page), all modules and page replications call the same five Api urls (category, status, severity, project and issue).
Both the API and the angular project are published and working in:
Api: http://clientes.tolitech.com.br/ngTestApi
Api Documentation: http://clientes.tolitech.com.br/ngTestApi/api-docs
Angular: http://clientes.tolitech.com.br/ngtest/
To download the source code:
http://www.codegenerator.com.br/downloads/ng-test.zip
filipesilva commentedon Nov 20, 2017
@tolitech whoa this is perfect, thank you so much! I'll use it to run some benchmarks and see what I can find. Will also try and trim it down to do a webpack issue for
ModuleConcatenationPluginso we can get the ball rolling there. This is great!WandererInVoids commentedon Nov 20, 2017
@filipesilva due your comment i commented out that lines memory usage decreased from 5.5 gb to 2.5 gb
filipesilva commentedon Nov 20, 2017
@WandererInVoids ok, that's a good sign. I'll keep pressing on this line of investigation.
@tolitech using your repo (CLI 1.4.1/ Angular 4.4.6 / TS 2.3.3) :
ng buildpeaks at 2.2GB ramng build --prodpeaks at 18.5GB ramThe memory usage per progress
%looks like this:I also tried to upgrade the repro to use CLI 1.5.2/ Angular 5.0.2 / TS 2.4.2.
ng buildpeaks at 2.3GB ramng build --prodpeaks at 22.0GB ramThe memory usage per progress
%looks like this:Note: using CLI 1.5 + Angular 5 defaults to using Build Optimizer on prod builds. I also noticed that the 92% phase took a lot longer than before like @changLiuUNSW reported, while memory usage kinda plateaued. It makes me think that
PurifyPlugin(part of Build Optimizer) is what takes so long here.For comparison, I also tried compiling the project using
ngcand it peaked at 3.3gb used memory. Comparing that to the 0-11% phase it looks like our compiler plugin doesn't add a significant overhead.tscitself peaks 830MB used memory.The project using Angular 5 can be found at https://github.com/filipesilva/angular-cli-test-repo.
Here's a breakdown of the project files by extension:
Looking at the peak memory usage numbers I can say a couple of things:
I'm going to follow up with the Webpack folks to see what's actually happening in that last phase.
@tolitech you've been a massive help getting to the bottom of this, I can't thank you enough 💯
Tragetaschen commentedon Nov 20, 2017
I don't get how 3.3 Gb memory for 1500 HTML files is reasonable. That's 2 Mb per file. Do these numbers contain collectable garbage or is this what's actually claimed until the end of the build?
kdubious commentedon Nov 20, 2017
@filipesilva My setup is like this:
CLI 1.5.2/ Angular 5.0.2 / TS 2.4.2
I use a few 3rd party packages.
ng build --prod : fails with the JavaScript heap out of memory error
ng --env=build --aot : works
emilio-martinez commentedon Nov 21, 2017
I ran into this issue. I was able to get a successful build with
node --max_old_space_size=8192 node_modules/.bin/ng build --prodAndreaBarbasso commentedon Nov 21, 2017
To add on @emilio-martinez's answer, on Windows use:
node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prodfinalxcode commentedon Nov 21, 2017
filipesilva commentedon Nov 21, 2017
@tolitech FYI I opened a webpack issue for the
ModuleConcatenationPluginmemory usage: webpack/webpack#5992.@Tragetaschen it's not just the HTML files, it's all the TS and code transformations too. The amount of memory used by the plugin (which is developed in this repo) is reasonable insofar as it is not a big overhead, 3 vs 3.3gb, over the
ngccompiler itself (which is developed in angular/angular).eduardotolino commentedon Nov 21, 2017
Thanks, @filipesilva
Taking advantage of the moment, I do not know if this would be the best time, but is there any technique for development to be improved?
Example: In a large project like this, a simple change in HTML or TS ends up taking a long time to reflect the onscreen settings. (ng serve -o running).
filipesilva commentedon Nov 21, 2017
@tolitech I'd like to talk about the different factors influencing dev rebuilds in big projects but would much prefer to do it in a separate issue. It's something that gets asked about frequently and it would be good to have discussion on it.
Can you open an issue called "Total rebuild time in medium and large projects", share your experience (rebuild time in the console but also time until app is ready in the browser), and ping me there please?
mattem commentedon Nov 21, 2017
@filipesilva I have tried commenting out the
ModuleConcaternationPluginand rerun our builds. In short our project still runs into memory issues.I don't know if this makes a difference, but the way our projects are currently setup we have a number of internal libraries that while in development, use
npm linkto link.Memory peaks at 2.51gb real / 7.26 virtual when running with the
ModuleConcaternationPlugincommented out.Full output:
I then tried with the
UglifyJsPlugincommented out:Memory peaks at 1.54gb real / 6.35 virtual.
The build completed without the need to add additional memory to Node.
I also tried running with
node --inspectand attaching the Chrome debugger to grab some heap snapshots and memory profiles, but it in my tests that caused the CLI to hang during the compilation stage with 1 module remaining.The other part that is hammering us is the time taken by the compile for tests, we have had to continually increase timeouts in the Karma conf, and the time taken for a page refresh with tests (during development) is quite high, mainly due to that ~15mb vendor bundle.
Tragetaschen commentedon Nov 21, 2017
@filipesilva I get that there is "stuff" that's generated, that's why I asked if these are clean numbers or if remaining garbage from the actual processing is still contained in that number.
If that's the actual number of bytes claimed, then I still don't get it: Assuming 2Kb per HTML file on average(!) (which is still much more than I would expect - I have 1 kb on average) then each single byte from those files (spaces, angular brackets, text characters, etc.) will generate 1000 bytes of transformed / generated content. I just cannot believe that's the case.
filipesilva commentedon Nov 21, 2017
@Tragetaschen the numbers I got were just looking at the task manager and keeping track of what the maximum used memory was. I'm not sure why you are focusing on the HTML templates though.
ngcdoes more than just compile templates.filipesilva commentedon Nov 21, 2017
@mattem if you're already reaching 1.54GB without Uglify/ModuleConcaternationPlugin, then it looks like your project as is needs more than the default node max memory. At how much memory does your project peak when doing just
ng build?filipesilva commentedon Nov 21, 2017
@mattem can you open an issue called "Total rebuild test time in medium and large projects", similar to the one I asked @tolitech to open in #5618 (comment)? It's a broader topic as well.
filipesilva commentedon Nov 21, 2017
@Tragetaschen I measured
tscpeak as well and it's 830MB. Bear in mind however thatngcboth compiles templates, transforms code, and generate new TS files. So total TS files processed would be around double. I pinged the team about the difference betweenngcandtsc.mattem commentedon Nov 21, 2017
@filipesilva Running
ng builduses 1.31gb real / 5.99 virtual peak.Here is the full output from the command
We don't run into memory issues (yet, I guess) when running development builds, we are generally experiencing the same as what @tolitech has already mentioned. (I'm keeping an keen eye on the progress of the Bazel building and the work being done there, happy to be a guinea pig for any of that)
Tragetaschen commentedon Nov 21, 2017
@filipesilva Just to be sure: It's not that I care about the HTML compilation step per se, it's that you claimed 3.3 GiB memory consumption just for HTML and NgModule processing "reasonable for project size". Using a thousand times the memory compared to the input data size while the resulting bundle (even without any further optimizations) is over an order of magnitude smaller just isn't reasonable.
Sure, there are bigger problems when it comes to memory consumption right now and I wish I could me more (well, any kind of) constructive, but the entire compilation process currently takes one or two orders of magnitude (!) more memory than I would call "reasonable".
markmaynard commentedon Nov 21, 2017
@Tragetaschen I think Felipe is commenting on your math. That step doesn't just involve the HTML file but includes the typescript and CSS files too. In order to properly uglify your entire project is brought into memory, so you can't just count the HTML. Additionally, some of your logic may cause duplication of subsets of your Dom, exploding the size. This is a complicated task that will take a good amount of RAM. We should use as little as possible, but we can't expect miracles.
mattem commentedon Nov 21, 2017
@filipesilva Opened issue #8579 for test rebuild times
dobrinsky commentedon Nov 28, 2017
I am also having the same issue. I can share my code to you @filipesilva
dereklin commentedon Nov 30, 2017
My --prod build works but slow. When I added --stats-json it ran out of memory. I got it working by doing this:
fix(@angular/cli): update webpack, uglifyjs-webpack-plugin
filipesilva commentedon Nov 30, 2017
We're updating the Webpack version used in the CLI in #8689 to include the fix for excessive memory usage in
ModuleConcatenationPlugin(webpack/webpack#5997).This will be available in the next release of Angular CLI and should address most of the reports of excessive memory usage in
1.3.xand up.I'd like to reiterate that it is expected that projects will reach the memory limit after a certain size. The bigger your project is, the more memory it will need to be built especially in
--prod.For those cases the recommendation is that you run the CLI with an increased memory limit via a
npmscript:Then you can do
npm run ng-high-mem -- build --prodto do a production build. Note the double dash (--), it is used innpmscripts to separate args.In this script the limit is increased to 8gigs. You can use a bigger number if you need.
Meanwhile we will keep on making improvements to reduce the memory footprint of the Angular CLI build system.
@changLiuUNSW I've opened a separate issue to track the excessive build time increase when using
--build-optimizer: angular/devkit#305.radoslavpetranov commentedon Nov 30, 2017
Thanks for taking the time to look into this in such detail @filipesilva! Much appreciated!
dobrinsky commentedon Nov 30, 2017
The problem is, this is my webpack.config:
`const path = require('path');
const webpack = require('webpack');
const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin;
const merge = require('webpack-merge');
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
module.exports = (env) => {
// Configuration in common to both client-side and server-side bundles
//const isDevBuild = !(env && env.prod);
const isDevBuild = true;
const sharedConfig = {
stats: { modules: false },
context: __dirname,
resolve: { extensions: [ '.js', '.ts' ] },
output: {
filename: '[name].js',
publicPath: 'dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
},
module: {
rules: [
{ test: /.ts$/, include: /ClientApp/, use: isDevBuild ? ['awesome-typescript-loader?silent=true', 'angular2-template-loader'] : '@ngtools/webpack' },
{ test: /.html$/, use: 'html-loader?minimize=false' },
{ test: /.css$/, use: [ 'to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize' ] },
{ test: /.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
]
},
plugins: [new CheckerPlugin()]
};
};
`
So, I am not using ModuleConcatenationPlugin and I still get the same error. That is why I offered my code
filipesilva commentedon Nov 30, 2017
@dobrinsky how many TS files do you have in your project? Do you know what is peak memory usage?
dobrinsky commentedon Nov 30, 2017
I have 240. Will get up to 400 probably until I finish the project.
No, I do not know. I am a beginner...I do not know how to find that out
filipesilva commentedon Nov 30, 2017
I usually run the build process, and then just look at the task manager to see how much memory the process is using. Peak memory usage is just the biggest number I saw for memory usage while the process was running.
dobrinsky commentedon Nov 30, 2017
:)))) I didn't knew it was that simple. Thought I need some software or something...
Anyway, the strangest thing happened:
I started with:
Then Visual Studio started using memory in the build process:
Then of course, Node started using too:
But my peak was 68%, with just 1.67 GB of memory usage
So, this is definitely something else
nadhir-falta commentedon Nov 30, 2017
Upgrading to Angular-CLI 1.5.5, Node to 8.9.1 and Yarn to 1.3.2 Fixed that issue for me.
And running Yarn did the fix better than npm.
dobrinsky commentedon Nov 30, 2017
I am not using Yarn. I have Node 9.2, but Angular-CLI 1.5.4.
I will try with 1.5.5
JasonPaape commentedon Nov 30, 2017
Thanks @filipesilva for your post above re: "ng-high-mem". I confirmed with my project that this does work and I no longer run out of memory during prod build with aot and build-optimizer on. Without this I ran out of memory.
package.json scripts:
"ng-high-mem": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng"
Now this works:
npm run ng-high-mem -- build --prod --aot=true --build-optimizer=true
Note in your msg above you wrote:
"Then you can do npm run ng-high-mem -- --prod to do a production build."
But I think you missed "build" in there:
npm run ng-high-mem -- build --prod
Jayaraj8905 commentedon Dec 1, 2017
Hi @filipesilva,
In our project we are having the out of memory issue with below version
@angular/cli: 1.2.0
@angular: 4.2.5
We are near production and we expect solution for this. Due to some constraints we couldn't able to migrate to angular 5 for now.
Is there any solution will be available for this?
filipesilva commentedon Dec 1, 2017
@dobrinsky have you tried running your webpack config with
node --max_old_space_size=8192to increase the memory limit? What is the maximum you see then? If it's just above the maximum you saw before it might just be that you need that little extra bit of memory.@JasonPaape thanks, I added it now!
@Jayaraj8905 at this point your best bet is to either use that script (
ng-high-mem) or update.1.2.0was a long time ago and we don't publish fixes for it anymore.JaapMosselman commentedon Dec 1, 2017
Using ng-high-mem option with @angular/cli 1.5.4 solved it for me.
Using @angular/cli 1.5.5, I saw 30-40% less memory usage, but still memory outage, so still ng-high-mem required for my build.
Now using ng-high-mem (with 8192) it is using a lot more memory. Is it using more when it has more memory available?
filipesilva commentedon Dec 1, 2017
Please bear in mind that the webpack update is not in yet. It will be in either
1.5.6or1.6.0.JaapMosselman commentedon Dec 1, 2017
Hopefully that will also speed up the production build a lot. I just migrated from the old Angular 2 way (ngc aot + rollup) to angular/cli and the build time grow from 4m to about 12m. :-(
fix(@angular/cli): update webpack, uglifyjs-webpack-plugin
HarelM commentedon Dec 1, 2017
I'm seeing this since the migration to angular 5 + angular-cli 1.5.5 on my CI build machine.
Thanks for the help of appveyor team I was able to use the
--max_old_space_sizeon the node cmd file.Relevant info can be found in the following discussion (which links here):
https://help.appveyor.com/discussions/problems/10192-out-of-memory-when-using-angular-cli-15-angular-5
And in this issue in my repository.
IsraelHikingMap/Site#567
fix(@angular/cli): update webpack, uglifyjs-webpack-plugin
kisdaniel commentedon Dec 2, 2017
I have a same issue with @angular/cli@1.5.5
kisdaniel commentedon Dec 3, 2017
adding to this line
"build-prod": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --prod",to
package.jsonhelped me.alvachien commentedon Dec 4, 2017
@filipesilva I saw a new version of webpack has been release days ago which ships your performance tuning code, when will angular-cli release a new version refer to the latest version of webpack? Thank you.
Koslun commentedon Dec 4, 2017
@alvachien In next version of Angular CLI, 1.5.6 or 1.6.0, is what he said just a little up in this thread.
Judging by latest releases I would assume that this could happen this week unless there is something in particular blocking it.
connorsleight commentedon Dec 4, 2017
@kisdaniel 's solution/workaround seems to work fine. its sorted my issues
wolfhoundjesse commentedon Dec 4, 2017
Increasing --max_old_space_size works for me, but after an hour or so, my RAM (32Gb) usage hits 70% or 80%, incremental builds slow down, and node or ng serve crashes.
filipesilva commentedon Dec 4, 2017
@wolfhoundjesse are you using AOT on rebuilds?
krassx commentedon Dec 4, 2017
Is there any ETA on release with aforementioned deps update? Fighting with this issue in our CI which doesn't have much RAM for now, so this fix is urgently required (I know I can hack package.json to point directly at master, but this is a hack I want to avoid).
filipesilva commentedon Dec 4, 2017
It should be in this weeks release, since we usually release once per week.
connorsleight commentedon Dec 4, 2017
@krassx for now, try @kisdaniel 's fix, works fine for an 8gb ram machine
krassx commentedon Dec 4, 2017
@mast3rd3mon, It doesn't help that much as we have 4GB RAM on our build machine. Will try to play with the limit to make it work.
connorsleight commentedon Dec 4, 2017
@krassx maybe try the same command but for 4gb ram? so 4096 not 8192
krassx commentedon Dec 4, 2017
Tried that. And got that out of memory error. It does work on my local machine (macOS, 8GM RAM) but fails on build machine (Linux, 4GB).
WandererInVoids commentedon Dec 4, 2017
@krassx try disable build optimizer and source map, can u share yours build command?
krassx commentedon Dec 4, 2017
This is what I use locally with no errors. But it fails on CI machine as I noted before.
WandererInVoids commentedon Dec 4, 2017
@krassx try this for production u can just use prod
node --max_old_space_size=4096 --stack_size=512 ./node_modules/@angular/cli/bin/ng build --prod -vc --build-optimizer=falserefer to this page for more option https://github.com/angular/angular-cli/wiki/build
krassx commentedon Dec 4, 2017
Ok, will give it a try. Thank you.
krassx commentedon Dec 4, 2017
@WandererInVoids, disabling build optimizer did the trick. Thank you for the advice.
WandererInVoids commentedon Dec 4, 2017
@krassx your welcome
fix(@angular/cli): update webpack, uglifyjs-webpack-plugin
filipesilva commentedon Dec 5, 2017
@angular/cli@1.6.0-rc.2is now released and includes the memory fix on Webpack's side.wolfhoundjesse commentedon Dec 5, 2017
@filipesilva I'm using
node --max_old_space_size=16384 node_modules/.bin/ng serve --aot. I'll upgrade to rc.2 now.PeS82 commentedon Dec 7, 2017
@filipesilva I am sorry , I am traveling and missed your question to me. To reply, yes, my problems started after updating to 1.5.0 and plain
ng build --prodfailed with any 1.5.x. I had to build, as many others, with raised memorynode --max-old-space-size=8192 node_modules\@angular\cli\bin\ng build --prod.Having said that at the same time as I updated to 1.5 I included 3rd party library that probably sent the build process over the edge.
And now the good news. I have just updated to 1.6 and the build finishes just fine with plain old
ng build --prod.Thanks.
FrancescoBorzi commentedon Dec 7, 2017
I can confirm this issue, it looks a serious one.
It happens only when AOT is enabled.
So it will work fine if I disable AOT and run:
ng build --prod --aot falseelclanrs commentedon Dec 7, 2017
1.6.0 seems to have fixed it for us. Our app compiled without extending the memory.
calebeaires commentedon Dec 7, 2017
@elclanrs not here, (1.6.0)
FrancescoBorzi commentedon Dec 7, 2017
apparently, upgrading to latest cli(1.6)/angular(5.1)/typescript(2.5) solved the issue
MrBlaise commentedon Dec 8, 2017
I upgraded to cli 1.6 and angular 5.1 and now our app could build under 1.7 gigs
seanlandsman commentedon Dec 8, 2017
@filipesilva a bit late, but I finally got around to testing ag-Grid with 1.6.0 and it all builds fine now.
Thanks for your hard work on this
alvachien commentedon Dec 8, 2017
@filipesilva I tried the 1.6.0, it seems my project work fine, thank you.
WandererInVoids commentedon Dec 8, 2017
@filipesilva don`t work for me but build time and memory usage decreased
aminebizid commentedon Dec 8, 2017
Now it’s time to switch to Bazel/Rollup
JaapMosselman commentedon Dec 11, 2017
I upgraded to cli 1.6 and angular 5.1.
The max memory the production build now using is around 1.3 GB. So no heap errors anymore.
Strange thing is that the process is 'hanging' at '92% chunk asset optimization' for 7 minutes of the total of 9 minutes buildtime.
What is happening there?
handark commentedon Dec 13, 2017
@Ristaaf thank you very much, your solution works perfect
pleerock commentedon Jan 3, 2018
We still have this issue. We had this issue since
angular@2when I first time used angular CLI. Then I switched to angular starter and everything worked. Now Im trying to use angular cli again on the same project (upgrade from angular 4) and now I still have same issue with angular 5.1 and cli1.6.2.We have a really huge project and we are using angular on this project from early versions of angular since 2013.
When I simply use
ng buildbuild is going 1 hour. Here is a log.When I use
ng buildI always have an error (after few minutes of build):If you want to know how many code and files we have:
filipesilva commentedon Jan 3, 2018
@pleerock have you tried using the command to increase max memory, on both prod and dev builds?
If your project is near to the maximum memory it will need a lot of GC and that slows down things. Increasing the max memory even when you're not hitting it (like in dev) should help.
pleerock commentedon Jan 3, 2018
@filipesilva thanks, it works. Both prod and dev builds. And build time is still 1 hour. Im glad that it works this way, however having to wait 1 hour each time is a problem. Also, its a big problem to run
ng serve. When we run it, it takes same 1 hour to start serving which makes development process completely impossible.filipesilva commentedon Jan 3, 2018
@pleerock yeah 1h for
ng serveis really odd. I have never seen such a large build time in any projects I've handled.I have reports of slow prod builds of that length (#6795) but haven't heard of anything like that just for
ng serve... I use https://github.com/filipesilva/angular-cli-test-repo as a benchmark for larger projects and it has around 2400 TS files, but still only takes a few minutes.Is your repro public or is there a way that I can see it?
filipesilva commentedon Jan 3, 2018
Another option would be to take a CPU profile (there's some instructions here #8259). But I wouldn't be surprised if the devtools crash, they usually do on huge jobs. Maybe a CPU profile of just a few minutes would be feasible?
pleerock commentedon Jan 3, 2018
no, its not public. If you can we can make a call and I can show you and maybe we can use teamviewer or similar things.
BTW,
76% basic chunk optimizationstep takes most of time (99%). If I runng serveand change a file it takes same 1 hour to rebuild everything.CPU profile of first 10 minutes of
76% basic chunk optimizationprocess (ng serve):CPU-20180103T195000.cpuprofile.zip