Files in `node_modules` are not authored by the user directly and the original sources are less relevant to the user. Skipping source maps in `node_modules` improves the general performance. Add `module.setSourceMapsSupport(enabled, options)` to skip source maps in `node_modules` if it is needed. This moves all source maps related API to `node:module` and this a step to promote the source maps API to stable. PR-URL: https://github.com/nodejs/node/pull/56639 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
const modPath = require.resolve('../fixtures/simple-error-stack.js');
|
|
const nodeModulePath = require.resolve('../fixtures/node_modules/error-stack/simple-error-stack.js');
|
|
const Module = require('node:module');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
method: [
|
|
'without-sourcemap',
|
|
'sourcemap',
|
|
'node-modules-without-sourcemap',
|
|
'node-module-sourcemap'],
|
|
n: [1e5],
|
|
});
|
|
|
|
function runN(n, modPath) {
|
|
delete require.cache[modPath];
|
|
const mod = require(modPath);
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
mod.simpleErrorStack();
|
|
}
|
|
bench.end(n);
|
|
}
|
|
|
|
function main({ n, method }) {
|
|
switch (method) {
|
|
case 'without-sourcemap':
|
|
process.setSourceMapsEnabled(false);
|
|
runN(n, modPath);
|
|
break;
|
|
case 'sourcemap':
|
|
process.setSourceMapsEnabled(true);
|
|
runN(n, modPath);
|
|
break;
|
|
case 'node-modules-without-sourcemap':
|
|
Module.setSourceMapsSupport(true, {
|
|
nodeModules: false,
|
|
});
|
|
runN(n, nodeModulePath);
|
|
break;
|
|
case 'node-modules-sourcemap':
|
|
Module.setSourceMapsSupport(true, {
|
|
nodeModules: true,
|
|
});
|
|
runN(n, nodeModulePath);
|
|
break;
|
|
default:
|
|
throw new Error(`Unexpected method "${method}"`);
|
|
}
|
|
}
|