mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
lib: allow skipping source maps in node_modules
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>
This commit is contained in:
parent
869d0cbca3
commit
b11ee4cad3
24 changed files with 491 additions and 48 deletions
|
@ -2,13 +2,19 @@
|
|||
|
||||
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'],
|
||||
method: [
|
||||
'without-sourcemap',
|
||||
'sourcemap',
|
||||
'node-modules-without-sourcemap',
|
||||
'node-module-sourcemap'],
|
||||
n: [1e5],
|
||||
});
|
||||
|
||||
function runN(n) {
|
||||
function runN(n, modPath) {
|
||||
delete require.cache[modPath];
|
||||
const mod = require(modPath);
|
||||
bench.start();
|
||||
|
@ -22,11 +28,23 @@ function main({ n, method }) {
|
|||
switch (method) {
|
||||
case 'without-sourcemap':
|
||||
process.setSourceMapsEnabled(false);
|
||||
runN(n);
|
||||
runN(n, modPath);
|
||||
break;
|
||||
case 'sourcemap':
|
||||
process.setSourceMapsEnabled(true);
|
||||
runN(n);
|
||||
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}"`);
|
||||
|
|
16
benchmark/fixtures/node_modules/error-stack/simple-error-stack.js
generated
vendored
Normal file
16
benchmark/fixtures/node_modules/error-stack/simple-error-stack.js
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
'use strict';
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.simpleErrorStack = simpleErrorStack;
|
||||
// Compile with `tsc --inlineSourceMap benchmark/fixtures/node_modules/error-stack/simple-error-stack.ts`.
|
||||
var lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
|
||||
function simpleErrorStack() {
|
||||
[1].map(function () {
|
||||
try {
|
||||
lorem.BANG();
|
||||
}
|
||||
catch (e) {
|
||||
return e.stack;
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2ltcGxlLWVycm9yLXN0YWNrLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsic2ltcGxlLWVycm9yLXN0YWNrLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLFlBQVksQ0FBQzs7QUFpQlgsNENBQWdCO0FBZmxCLGlGQUFpRjtBQUVqRixJQUFNLEtBQUssR0FBRywrYkFBK2IsQ0FBQztBQUU5YyxTQUFTLGdCQUFnQjtJQUN2QixDQUFDLENBQUMsQ0FBQyxDQUFDLEdBQUcsQ0FBQztRQUNOLElBQUksQ0FBQztZQUNGLEtBQWEsQ0FBQyxJQUFJLEVBQUUsQ0FBQztRQUN4QixDQUFDO1FBQUMsT0FBTyxDQUFDLEVBQUUsQ0FBQztZQUNYLE9BQU8sQ0FBQyxDQUFDLEtBQUssQ0FBQztRQUNqQixDQUFDO0lBQ0gsQ0FBQyxDQUFDLENBQUE7QUFDSixDQUFDIn0=
|
19
benchmark/fixtures/node_modules/error-stack/simple-error-stack.ts
generated
vendored
Normal file
19
benchmark/fixtures/node_modules/error-stack/simple-error-stack.ts
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
// Compile with `tsc --inlineSourceMap benchmark/fixtures/node_modules/error-stack/simple-error-stack.ts`.
|
||||
|
||||
const lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
|
||||
|
||||
function simpleErrorStack() {
|
||||
[1].map(() => {
|
||||
try {
|
||||
(lorem as any).BANG();
|
||||
} catch (e) {
|
||||
return e.stack;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export {
|
||||
simpleErrorStack,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue