Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions 60 benchmark/source_map/source-map-cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict';

const common = require('../common.js');
const assert = require('assert');
const fixtures = require('../../test/common/fixtures');

const bench = common.createBenchmark(
main,
{
operation: [
'findSourceMap-valid',
'findSourceMap-generated-source',
],
n: [1e5],
},
);

function main({ operation, n }) {
const Module = require('node:module');

Module.setSourceMapsSupport(true, {
generatedCode: true,
});
const validFileName = fixtures.path('test-runner/source-maps/line-lengths/index.js');

const fileNameKey = '/source-map/disk.js';
const generatedFileName = fixtures.path(fileNameKey);
const generatedFileContent = fixtures.readSync(fileNameKey, 'utf8');
const sourceMapUrl = generatedFileName.replace(/\.js$/, '.map');
const sourceWithGeneratedSourceMap =
`${generatedFileContent}\n//# sourceMappingURL=${sourceMapUrl}\n//# sourceURL=${generatedFileName}`;
const generatedExpectedUrl = `file://${generatedFileName}`;

let sourceMap;
switch (operation) {
case 'findSourceMap-valid':
require(validFileName);

bench.start();
for (let i = 0; i < n; i++) {
sourceMap = Module.findSourceMap(validFileName);
}
bench.end(n);
break;

case 'findSourceMap-generated-source':
eval(sourceWithGeneratedSourceMap);

bench.start();
for (let i = 0; i < n; i++) {
sourceMap = Module.findSourceMap(generatedExpectedUrl);
}
bench.end(n);
break;

default:
throw new Error(`Unknown operation: ${operation}`);
}
assert.ok(sourceMap);
}
95 changes: 95 additions & 0 deletions 95 benchmark/source_map/source-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
'use strict';

const common = require('../common.js');
const assert = require('assert');
const fixtures = require('../../test/common/fixtures');

const bench = common.createBenchmark(
main,
{
operation: [
'parse',
'parse-sectioned',
'findEntry',
'findEntry-sectioned',
'findOrigin',
'findOrigin-sectioned',
],
n: [1e5],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
n: [1e5],
n: [1e5],

Is this an arbitrary number, or did you find that this is the curve where benchmark results do not change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I had some testing for 10 up to 1e8 and it stabilizes around 1e5.

For source-map-cache

source_map/source-map-cache.js n=10 operation="findSourceMap-valid": 22,044.640396803527
source_map/source-map-cache.js n=100 operation="findSourceMap-valid": 114,264.03676559647
source_map/source-map-cache.js n=1000 operation="findSourceMap-valid": 135,848.8002852825
source_map/source-map-cache.js n=10000 operation="findSourceMap-valid": 425,194.9252985665
source_map/source-map-cache.js n=100000 operation="findSourceMap-valid": 661,039.200292227
source_map/source-map-cache.js n=1000000 operation="findSourceMap-valid": 655,766.5874586097
source_map/source-map-cache.js n=10000000 operation="findSourceMap-valid": 686,861.3520220064
source_map/source-map-cache.js n=100000000 operation="findSourceMap-valid": 690,901.4430697807

source_map/source-map-cache.js n=10 operation="findSourceMap-generated-source": 19,123.493785820694
source_map/source-map-cache.js n=100 operation="findSourceMap-generated-source": 222,985.82479111804
source_map/source-map-cache.js n=1000 operation="findSourceMap-generated-source": 1,262,360.0831642824
source_map/source-map-cache.js n=10000 operation="findSourceMap-generated-source": 3,751,348.609825232
source_map/source-map-cache.js n=100000 operation="findSourceMap-generated-source": 4,789,673.464011591
source_map/source-map-cache.js n=1000000 operation="findSourceMap-generated-source": 5,322,983.097883862
source_map/source-map-cache.js n=10000000 operation="findSourceMap-generated-source": 3,526,343.638308575
source_map/source-map-cache.js n=100000000 operation="findSourceMap-generated-source": 5,725,883.259174296

For source-map

source_map/source-map.js n=10 operation="parse": 24,502.29709035222
source_map/source-map.js n=100 operation="parse": 94,723.07236179667
source_map/source-map.js n=1000 operation="parse": 172,707.84309492455
source_map/source-map.js n=10000 operation="parse": 353,478.6719806294
source_map/source-map.js n=100000 operation="parse": 454,661.1017299623
source_map/source-map.js n=1000000 operation="parse": 502,081.0841701146
source_map/source-map.js n=10000000 operation="parse": 503,396.77038754406
source_map/source-map.js n=100000000 operation="parse": 500,985.0726477283
source_map/source-map.js n=10 operation="parse-sectioned": 21,158.42369743454
source_map/source-map.js n=100 operation="parse-sectioned": 28,618.788578127005
source_map/source-map.js n=1000 operation="parse-sectioned": 121,799.59387143419
source_map/source-map.js n=10000 operation="parse-sectioned": 230,234.37859741217
source_map/source-map.js n=100000 operation="parse-sectioned": 310,112.7780007161
source_map/source-map.js n=1000000 operation="parse-sectioned": 335,803.14216158056
source_map/source-map.js n=10000000 operation="parse-sectioned": 323,348.8163390162
source_map/source-map.js n=100000000 operation="parse-sectioned": 318,926.62476153404
source_map/source-map.js n=10 operation="findEntry": 167,364.01673640168
source_map/source-map.js n=100 operation="findEntry": 1,203,615.6614469867
source_map/source-map.js n=1000 operation="findEntry": 2,766,573.156493977
source_map/source-map.js n=10000 operation="findEntry": 6,595,762.22277187
source_map/source-map.js n=100000 operation="findEntry": 34,166,132.82084134
source_map/source-map.js n=1000000 operation="findEntry": 66,372,785.67112444
source_map/source-map.js n=10000000 operation="findEntry": 69,998,661.2756031
source_map/source-map.js n=100000000 operation="findEntry": 74,137,195.965463
source_map/source-map.js n=10 operation="findEntry-sectioned": 157,895.56787140985
source_map/source-map.js n=100 operation="findEntry-sectioned": 1,099,408.518217199
source_map/source-map.js n=1000 operation="findEntry-sectioned": 3,204,265.518257905
source_map/source-map.js n=10000 operation="findEntry-sectioned": 13,917,070.957577985
source_map/source-map.js n=100000 operation="findEntry-sectioned": 32,089,851.58443642
source_map/source-map.js n=1000000 operation="findEntry-sectioned": 62,772,341.727857664
source_map/source-map.js n=10000000 operation="findEntry-sectioned": 68,942,219.52581541
source_map/source-map.js n=100000000 operation="findEntry-sectioned": 66,538,906.42142866
source_map/source-map.js n=10 operation="findOrigin": 129,379.49593748382
source_map/source-map.js n=100 operation="findOrigin": 902,934.5372460497
source_map/source-map.js n=1000 operation="findOrigin": 2,388,293.540382461
source_map/source-map.js n=10000 operation="findOrigin": 12,155,586.646844957
source_map/source-map.js n=100000 operation="findOrigin": 30,224,035.664362084
source_map/source-map.js n=1000000 operation="findOrigin": 54,367,277.162258655
source_map/source-map.js n=10000000 operation="findOrigin": 61,682,814.88834895
source_map/source-map.js n=100000000 operation="findOrigin": 65,709,915.70638048
source_map/source-map.js n=10 operation="findOrigin-sectioned": 133,184.16706621918
source_map/source-map.js n=100 operation="findOrigin-sectioned": 766,530.2242867437
source_map/source-map.js n=1000 operation="findOrigin-sectioned": 2,399,042.3023129166
source_map/source-map.js n=10000 operation="findOrigin-sectioned": 5,187,171.295438972
source_map/source-map.js n=100000 operation="findOrigin-sectioned": 16,531,884.963870391
source_map/source-map.js n=1000000 operation="findOrigin-sectioned": 50,945,463.747131586
source_map/source-map.js n=10000000 operation="findOrigin-sectioned": 41,329,287.598349184
source_map/source-map.js n=100000000 operation="findOrigin-sectioned": 60,279,529.754421346

},
);

function main({ operation, n }) {
const { SourceMap } = require('node:module');

const samplePayload = JSON.parse(
fixtures.readSync('source-map/no-source.js.map', 'utf8'),
);
const sectionedPayload = JSON.parse(
fixtures.readSync('source-map/disk-index.map', 'utf8'),
);

let sourceMap;
let sourceMapMethod;
switch (operation) {
case 'parse':
bench.start();
for (let i = 0; i < n; i++) {
sourceMap = new SourceMap(samplePayload);
}
bench.end(n);
break;

case 'parse-sectioned':
bench.start();
for (let i = 0; i < n; i++) {
sourceMap = new SourceMap(sectionedPayload);
}
bench.end(n);
break;

case 'findEntry':
sourceMap = new SourceMap(samplePayload);
bench.start();
for (let i = 0; i < n; i++) {
sourceMapMethod = sourceMap.findEntry(i, i);
}
bench.end(n);
assert.ok(sourceMapMethod);
break;

case 'findEntry-sectioned':
sourceMap = new SourceMap(sectionedPayload);
bench.start();
for (let i = 0; i < n; i++) {
sourceMapMethod = sourceMap.findEntry(i, i);
}
bench.end(n);
assert.ok(sourceMapMethod);
break;

case 'findOrigin':
sourceMap = new SourceMap(samplePayload);
bench.start();
for (let i = 0; i < n; i++) {
sourceMapMethod = sourceMap.findOrigin(i, i);
}
bench.end(n);
assert.ok(sourceMapMethod);
break;

case 'findOrigin-sectioned':
sourceMap = new SourceMap(sectionedPayload);
bench.start();
for (let i = 0; i < n; i++) {
sourceMapMethod = sourceMap.findOrigin(i, i);
}
bench.end(n);
assert.ok(sourceMapMethod);
break;

default:
throw new Error(`Unknown operation: ${operation}`);
}
assert.ok(sourceMap);
}
7 changes: 7 additions & 0 deletions 7 test/benchmark/test-benchmark-source-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

require('../common');

const runBenchmark = require('../common/benchmark');

runBenchmark('source_map', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.