Visitar URL original
Angular 12 compiler memory hungry · Issue #42960 · angular/angular · GitHub
The Wayback Machine - https://web.archive.org/web/20211006173803/https://github.com/angular/angular/issues/42960
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular 12 compiler memory hungry #42960

Closed
DanielKucal opened this issue Jul 26, 2021 · 8 comments
Closed

Angular 12 compiler memory hungry #42960

DanielKucal opened this issue Jul 26, 2021 · 8 comments

Comments

@DanielKucal
Copy link
Contributor

@DanielKucal DanielKucal commented Jul 26, 2021 •

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

Yes

Description

After upgrading to Angular 12 (from 11) ng build --configuration dev started to fail due to lack of memory. The same behavior can be seen on Azure and local environment. I tried to increase --max-old-space-size - still failed for 2GB, passed with 4GB on local machine. Before it was running fine on node's defaults. Probably this is something about sourceMap, because production build with them turned off works fine.

angular.json configurations:

"configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "7mb",
                  "maximumError": "8mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb"
                }
              ],
              "serviceWorker": true,
              "ngswConfigPath": "ngsw-config.json"
            },
            "dev": {
              "optimization": true,
              "outputHashing": "all",
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "7mb",
                  "maximumError": "8mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb"
                }
              ]
            }
          },
          "defaultConfiguration": ""
        },

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

ADDED: Full logs from another try: https://pastebin.com/raw/G7YqzXD9

/usr/local/bin/npm run build

> bgi-mobile@0.0.0 build /home/vsts/work/1/s
> ng build --configuration dev

- Generating browser application bundles (phase: setup)...
Compiling @angular/service-worker : es2015 as esm2015
Compiling @ngx-ext/google-analytics : es2015 as esm2015
Compiling @progress/kendo-angular-menu : es2015 as esm2015
Compiling @tinymce/tinymce-angular : es2015 as esm2015
Compiling ngx-sanitizer : es2015 as esm2015

<--- Last few GCs --->


[4106:0x5b0b850]   109070 ms: Mark-sweep (reduce) 2031.7 (2051.0) -> 2018.1 (2052.0) MB, 1629.8 / 0.1 ms  (+ 0.0 ms in 25 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 1834 ms) (average mu = 0.233, current mu = 0.194) [4106:0x5b0b850]   109077 ms: Scavenge (reduce) 2019.7 (2051.0) -> 2018.8 (2052.0) MB, 2.5 / 0.0 ms  (average mu = 0.233, current mu = 0.194) allocation failure 


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0xa222f0 node::Abort() [ng build --configuration dev]
 2: 0x96411f node::FatalError(char const*, char const*) [ng build --configuration dev]
 3: 0xb97f1e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [ng build --configuration dev]
 4: 0xb98297 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [ng build --configuration dev]
 5: 0xd52fd5  [ng build --configuration dev]
 6: 0xd53b5f  [ng build --configuration dev]
 7: 0xd61beb v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [ng build --configuration dev]
 8: 0xd657ac v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [ng build --configuration dev]
 9: 0xd33e5b v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [ng build --configuration dev]
10: 0x107c5af v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [ng build --configuration dev]
11: 0x1423279  [ng build --configuration dev]
Aborted (core dumped)
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! bgi-mobile@0.0.0 build: `ng build --configuration dev`
npm ERR! Exit status 134
npm ERR! 
npm ERR! Failed at the bgi-mobile@0.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vsts/.npm/_logs/2021-07-24T12_48_03_482Z-debug.log
Found npm debug log, make sure the path matches with the one in npm's output: /home/vsts/.npm/_logs/2021-07-24T12_48_03_482Z-debug.log

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
2 info using npm@6.14.13
3 info using node@v14.17.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle bgi-mobile@0.0.0~prebuild: bgi-mobile@0.0.0
6 info lifecycle bgi-mobile@0.0.0~build: bgi-mobile@0.0.0
7 verbose lifecycle bgi-mobile@0.0.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle bgi-mobile@0.0.0~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/vsts/work/1/s/node_modules/.bin:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/vsts/.local/bin:/usr/share/rust/.cargo/bin:/home/vsts/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/vsts/.dotnet/tools:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle bgi-mobile@0.0.0~build: CWD: /home/vsts/work/1/s
10 silly lifecycle bgi-mobile@0.0.0~build: Args: [ '-c', 'ng build --configuration dev' ]
11 silly lifecycle bgi-mobile@0.0.0~build: Returned: code: 134  signal: null
12 info lifecycle bgi-mobile@0.0.0~build: Failed to exec build script
13 verbose stack Error: bgi-mobile@0.0.0 build: `ng build --configuration dev`
13 verbose stack Exit status 134
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:376:20)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:376:20)
13 verbose stack     at maybeClose (internal/child_process.js:1055:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
14 verbose pkgid bgi-mobile@0.0.0
15 verbose cwd /home/vsts/work/1/s
16 verbose Linux 4.15.0-1113-azure
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
18 verbose node v14.17.0
19 verbose npm  v6.14.13
20 error code ELIFECYCLE
21 error errno 134
22 error bgi-mobile@0.0.0 build: `ng build --configuration dev`
22 error Exit status 134
23 error Failed at the bgi-mobile@0.0.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 134, true ]

##[error]Error: Npm failed with return code: 134
Finishing: npm build

Please provide the environment you discovered this bug in

Angular CLI: 12.1.2
Node: 14.15.1
Package Manager: npm 7.19.1
OS: darwin x64

Angular: 12.1.3
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router, service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1201.2
@angular-devkit/build-angular   12.1.2
@angular-devkit/core            12.1.2
@angular-devkit/schematics      12.1.2
@angular/cli                    12.1.2
@schematics/angular             12.1.2
rxjs                            6.6.7
typescript                      4.2.4

Anything else?

Should I attach something more?

@DanielKucal DanielKucal changed the title Angular 12 memory hungry Angular 12 compiler memory hungry Jul 26, 2021
@JoostK
Copy link
Member

@JoostK JoostK commented Jul 26, 2021 •

This sounds like angular/angular-cli#21381 for which it's not yet clear what the cause is. One of the things that has been established is that Terser in Webpack 5 is no longer forking subprocesses but instead uses Node workers, which operate in the same process and therefore contribute to memory usage of the main process. This was not the case with forked processes, as each process will then have its own memory pool (but the overall memory usage is higher).

I notice in your dev configuration that both optimization and buildOptimizer are enabled, is that intentional?

@ngbot ngbot bot added this to the needsTriage milestone Jul 26, 2021
@ngbot ngbot bot removed this from the needsTriage milestone Jul 28, 2021
@ngbot ngbot bot added this to the Backlog milestone Jul 28, 2021
@DanielKucal
Copy link
Contributor Author

@DanielKucal DanielKucal commented Jul 28, 2021 •

I notice in your dev configuration that both optimization and buildOptimizer are enabled, is that intentional?

@JoostK, yes, I guess so, is there something wrong with that? This is config for a build that runs a on a dev-test server.

@JoostK
Copy link
Member

@JoostK JoostK commented Jul 28, 2021

No that's fine, I was thinking it was used for live development purposes.

I do suspect that it's indeed Terser's memory usage that has been shifted to the main process that is the root cause for the OOM, not the Angular compiler itself. That would be something for the CLI repo to track, which I believe is covered by angular/angular-cli#21381.

@splincode
Copy link
Contributor

@splincode splincode commented Aug 1, 2021

@232650413

This comment was marked as spam.

@232650413

This comment was marked as spam.

@JoostK
Copy link
Member

@JoostK JoostK commented Aug 19, 2021

Closing for now as without a repro this isn't actionable for us. Still, it's likely (but I don't know for sure) that it's the reshuffling of Terser processes that has shifted the memory from multiple processes to just a single process. That increases the memory usage of that processed but is a sytem-wide reduction, as there is no longer the overhead of multiple Node processes.

@JoostK JoostK closed this Aug 19, 2021
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Sep 19, 2021

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants