Angular CLI - ng serve - high cpu usage from node process
In Angular development context; transpilation/compilation causes CPU spike. When this happens too frequent, your system is in trouble.
There are certain ways to relieve the pain a little;
- Turn off file change detection / live-reload / auto compilation entirely
ng serve --live-reload false
or ng serve --no-live-reload
etc. depending on your Angular CLI version
- Have a better change detection, react only when really needed
npm install fsevents
npm rebuild fsevents
npm serve
- Forget change detection, check changes based on a time interval
ng serve --poll [ms]
CPU management is tricky, there can be many reasons for this problem. These are only a few possibilities closely related to Angular development. I hope this answer provides some options to try to the ones having the same trouble.
Maybe you have similar setup for you hot/live reloading on Docker
such as ng serve --host 0.0.0.0 --poll 1
. The poll
value is problematic, change it on something larger, for example 2000
, such that ng serve --host 0.0.0.0 --poll 2000
.
Now, you'll loose (almost) real-time hot/live reloading, but you'll save your CPU/battery and having 2 seconds delay before your app will refresh the changed code.