Memory usage of node process for ng test/serve is very high
Bug Report or Feature Request (mark with an x)
- [x] bug report -> please search issues before submitting
- [ ] feature request
Versions.
ng --version
_ _ ____ _ ___
/ \ _ __ __ _ _ | | __ _ _ __ / | | | |
/ △ \ | ' \ / _ | | | | |/ _ | '| | | | | | |
/ ___ | | | | (| | || | | (| | | | || | | |
// __| ||_, |_,||_,|| _|||
|___/
@angular/cli: 1.0.0-rc.2
node: 6.10.1
os: win32 x64 (Win10)
@angular/common: 2.4.10
@angular/compiler: 2.4.10
@angular/core: 2.4.10
@angular/forms: 2.4.10
@angular/http: 2.4.10
@angular/material: 2.0.0-beta.2
@angular/platform-browser: 2.4.10
@angular/platform-browser-dynamic: 2.4.10
@angular/router: 3.4.10
@angular/cli: 1.0.0-rc.2
@angular/compiler-cli: 2.4.10
Repro steps.
Run npm test or npm start which runs ng test / ng serve
The log given by the failure.
Memory usage for each node process is between 600MB and 1000MB. That's a lot, I think, although the application is really small (about 500 lines of code).
Desired functionality.
I can't believe that this high memory usage is intended.
Mention any other details that might be useful.
Do you need a dump file?
This has been the case for a while, so in that sense it is intended (e.g. not a bug).
I do agree it's quite a bit and there's probably room for improvement there.
With a reasonably large project I get OOM when the process hits Node's memory limit. Since you can't set Node's memory limit via env var, I have to dig around manually to run the tests.
ƒ ng test
<--- Last few GCs --->
42309 ms: Mark-sweep 1364.9 (1435.8) -> 1364.7 (1435.8) MB, 1728.3 / 0.0 ms [allocation failure] [GC in old space requested].
43288 ms: Mark-sweep 1364.7 (1435.8) -> 1364.7 (1435.8) MB, 978.5 / 0.0 ms [allocation failure] [GC in old space requested].
44370 ms: Mark-sweep 1364.7 (1435.8) -> 1366.6 (1413.8) MB, 1081.1 / 0.0 ms [last resort gc].
45379 ms: Mark-sweep 1366.6 (1413.8) -> 1368.9 (1413.8) MB, 1009.0 / 0.0 ms [last resort gc].
@timruffles Yes, the memory usage of npm install is also crazy. But this is another topic.
Is the problem that developers don't understand that JSON-objects in memory need memory and isn't just a virtual, magic document from outer space ;-)
Running two concurrent ng serves, I had to increase the memory allocated for Docker from 2 GB to 4 GB just to prevent OOMing. This seems really wrong. Is it loading all of node_modules into RAM or something?
Agree. @angular/cli makes my laptop's fans getting crazy.
I've made comparison of pure Webpack setup, create-react-app and @angular/cli and cli is much worse. Any ideas?
This issue is rather old but I've never had a problem on my local setup until recently updating to CLI v1.3.0
It's running on macOS Sierra 10.12.6 and I have to restart ng serve twice a day because node runs out of memory.
The apps size is about 150 components, no big dependencies other than angular material.
Since there isnt a suitable recent ticket I can +1, im adding that we're having major issues with Jenkins and angular builds taking up way too much memory and causing the no response in 20000ms issue. From looking at the resources, excessive RAM usage from angular cli and npm seems to be the cause during builds
No solution for angular but I'm using now npm 5.4.2 and this version and some before (5.x.y) are much faster and use less memory.
I also have gotten to where I'm constantly restarting my ng serve due to it running out of memory, and my app isn't very large at all, perhaps 30 components, plus Angular Material.
I'm on @angular/cli v 1.5.0 | node 6.12.0 | npm 5.4.2, and ng serve uses 1.1Gb of RAM... what the hell?!
Any update? Same issue using 'ng serve --hmr'
Same problem here !!!! When you make changes it will swell !!! It starts low, every time it changes some file it increases.

Same issue. system freezes.
+1
This softens the situation: node --max_old_space_size=512 "./node_modules/@angular/cli/bin/ng" serve Put in packeage.json in scripts....
Same here, working with latest version of all.. With about 15 components and 3 services getting 3 gb of ram consumption an browser is freezing..
+1, Same issue with me, every day need close and open Angular, my project based on Nebular ngx-Admin, about 30~40 components, any update on this issue?
Version details as below
Node: 8.11.3
OS: win32 x64
Angular: 6.0.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
@angular-devkit/architect 0.8.3 @angular-devkit/build-angular 0.8.3 @angular-devkit/build-optimizer 0.8.3 @angular-devkit/build-webpack 0.8.3 @angular-devkit/core 0.8.3 @angular-devkit/schematics 0.8.3 @angular/cdk 5.2.5 @angular/cli 6.2.3 @ngtools/webpack 6.2.3 @schematics/angular 0.8.3 @schematics/update 0.8.3 rxjs 6.2.2 typescript 2.7.2 webpack 4.20.2
Memory running out was happening to me because I had a serializer file with a function returning an object with several entries.
function(obj) {
return {
key1: value1,
key2: value2,
...
key30: value30,
...
}
Also, some features in VS Code stopped working just by opening this file. After examining its Process Explorer, VS Code's tsserver process was utilizing an enormous amount of memory (it was exploding when opening that file and not decreasing after closing it). So in my case the issue was probably related to TypeScript.
I fixed just using Object.assign() instead of returning an object directly.
+1
I have a similar issue. I cant run typescript compilation after deploy on an EC2 instance with 1gb of ram (900+mb free), even with all optimizations turned off. It runs out of memory and crashes almost instantly.
"optimization": false,
"outputHashing": "all",
"sourceMap": false,
"extractCss": false,
"namedChunks": false,
"aot": false,
"extractLicenses": false,
"vendorChunk": false,
"buildOptimizer": false