Skip to content

Commit

Permalink
fix(perf): enable compile cache if present (#7901)
Browse files Browse the repository at this point in the history
Adding support to
[module.enableCompileCache](https://nodejs.org/docs/v22.11.0/api/module.html#moduleenablecompilecachecachedir),
added by nodejs/node#54501, Typescript got [2.5x
perf on
tsc](https://devblogs.microsoft.com/typescript/announcing-typescript-5-7-beta/#support-for-v8-compile-caching-in-node.js).

On my machine, for the command `--version`, I got the following results:

```bash
Benchmark 1: node bin/npm-cli.js --version
  Time (mean ± σ):      58.0 ms ±   1.1 ms    [User: 51.8 ms, System: 16.8 ms]
  Range (min … max):    56.5 ms …  62.6 ms    51 runs
 
Benchmark 2: node bin/npm-cli-with-cache.js --version
  Time (mean ± σ):      52.9 ms ±   1.0 ms    [User: 46.5 ms, System: 16.8 ms]
  Range (min … max):    51.4 ms …  55.5 ms    56 runs
 
Summary
  'node bin/npm-cli-with-cache.js --version' ran
    1.10 ± 0.03 times faster than 'node bin/npm-cli.js --version'
```

I run the same test with `npm run empty` and I got the same 10%
improvement.
  • Loading branch information
H4ad authored Nov 20, 2024
1 parent ec57f5f commit e19bff0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
try {
const { enableCompileCache } = require('node:module')
/* istanbul ignore next */
if (enableCompileCache) {
enableCompileCache()
}
} catch (e) { /* istanbul ignore next */ }

const validateEngines = require('./cli/validate-engines.js')
const cliEntry = require('node:path').resolve(__dirname, 'cli/entry.js')

Expand Down

0 comments on commit e19bff0

Please sign in to comment.