-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src,lib: reducing C++ calls of esm legacy main resolve
Instead of many C++ calls, now we make only one C++ call to return a enum number that represents the selected state.
- Loading branch information
Showing
5 changed files
with
358 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Tests the impact on eager operations required for policies affecting | ||
// general startup, does not test lazy operations | ||
'use strict'; | ||
const fs = require('node:fs'); | ||
const path = require('node:path'); | ||
const common = require('../common.js'); | ||
|
||
const tmpdir = require('../../test/common/tmpdir.js'); | ||
const { pathToFileURL } = require('node:url'); | ||
|
||
const benchmarkDirectory = | ||
path.resolve(tmpdir.path, 'benchmark-import-meta-resolve'); | ||
|
||
const configs = { | ||
n: [1e4], | ||
packageJsonUrl: [ | ||
'node_modules/test/package.json', | ||
], | ||
packageConfigMain: ['', './index.js'], | ||
resolvedFile: [ | ||
'node_modules/test/index.js', | ||
'node_modules/test/index.json', | ||
'node_modules/test/index.node', | ||
'node_modules/non-exist', | ||
], | ||
}; | ||
|
||
const options = { | ||
flags: ['--expose-internals'], | ||
}; | ||
|
||
const bench = common.createBenchmark(main, configs, options); | ||
|
||
function main(conf) { | ||
const { legacyMainResolve } = require('internal/modules/esm/resolve'); | ||
tmpdir.refresh(); | ||
|
||
fs.mkdirSync(path.join(benchmarkDirectory, 'node_modules', 'test'), { recursive: true }); | ||
fs.writeFileSync(path.join(benchmarkDirectory, conf.resolvedFile), '\n'); | ||
|
||
const packageJsonUrl = pathToFileURL(conf.packageJsonUrl); | ||
const packageConfigMain = { main: conf.packageConfigMain }; | ||
|
||
bench.start(); | ||
|
||
for (let i = 0; i < conf.n; i++) { | ||
try { | ||
legacyMainResolve(packageJsonUrl, packageConfigMain, undefined); | ||
} catch { /* empty */ } | ||
} | ||
|
||
bench.end(conf.n); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.