vercel / ncc

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.
https://npmjs.com/@vercel/ncc
MIT License
9.13k stars 287 forks source link

NCC consumes too much memory, can't be used with github pipelines #784

Open Yehonal opened 3 years ago

Yehonal commented 3 years ago

I'm using this command: ncc -m -s src/index.js to compile a large project in a single javascript bundle. However, it doesn't work in github pipelines since their containers are limited to 2 GB of ram causing a "memory heap" error during compilation.

I've tested locally by using this command: /usr/bin/time --format "%M" ncc -m -s src/index.js

And this is the result:

34630kB  env/dist/apps/manage-panel/bundle/index.js
90543kB  [146603ms] - ncc 0.31.1
4710052

4710052 -> It means that ncc consumes 4.7GB of ram to compile.

To reduce this amount I have to:

  1. disable the cache (-500Mb)
  2. disable the minification
  3. disable the sourcemap

doing so, the memory consumed is 1.5GB (which is fine for github

By the way, despite cache that should be disabled in pipelines, minification and sourcemap together are consume way too much. Is there a way to improve this?

styfle commented 3 years ago

This sounds like a duplicate of #596

Yehonal commented 3 years ago

Kind of, source map is the less problematic (it also adds ~500MB) but the minification adds ~3.5 GB

styfle commented 3 years ago

The minification currently uses terser, but we can look into using swc instead (experimental branch in #777)