@@ -7,34 +7,41 @@ const { spawnSync } = require('child_process');
77const tmpdir = require ( '../../test/common/tmpdir' ) ;
88
99const bench = common . createBenchmark ( main , {
10- modules : [ 250 , 500 , 1000 , 2000 ] ,
10+ modules : [ '0250' , '0500' , ' 1000' , ' 2000' ] ,
1111 n : [ 30 ] ,
1212} ) ;
1313
14+ const BRANCHING_FACTOR = 10 ;
15+
1416function prepare ( count ) {
1517 tmpdir . refresh ( ) ;
1618 const dir = tmpdir . resolve ( 'esm-graph' ) ;
1719 fs . mkdirSync ( dir , { recursive : true } ) ;
1820
19- // Create a flat ESM graph: entry imports all modules directly.
20- // Each module is independent, maximizing the number of resolve/load/link
21- // operations in the loader pipeline.
22- const imports = [ ] ;
23- for ( let i = 0 ; i < count ; i ++ ) {
24- fs . writeFileSync (
25- path . join ( dir , `mod${ i } .mjs` ) ,
26- `export const value${ i } = ${ i } ;\n` ,
27- ) ;
28- imports . push ( `import './mod${ i } .mjs';` ) ;
21+ // Create a tree-shaped ESM graph with a branching factor of 10.
22+ // The root (mod0) plus `count` additional modules are created in BFS order.
23+ // Module i imports modules BRANCHING_FACTOR*i+1 through
24+ // BRANCHING_FACTOR*i+BRANCHING_FACTOR (capped at count), so the graph is a
25+ // complete 10-ary tree rooted at mod0.
26+ const total = count + 1 ;
27+ for ( let i = 0 ; i < total ; i ++ ) {
28+ const children = [ ] ;
29+ for ( let c = 1 ; c <= BRANCHING_FACTOR ; c ++ ) {
30+ const child = BRANCHING_FACTOR * i + c ;
31+ if ( child < total ) {
32+ children . push ( `import './mod${ child } .mjs';` ) ;
33+ }
34+ }
35+ const content = children . join ( '\n' ) + ( children . length ? '\n' : '' ) +
36+ `export const value${ i } = ${ i } ;\n` ;
37+ fs . writeFileSync ( path . join ( dir , `mod${ i } .mjs` ) , content ) ;
2938 }
3039
31- const entry = path . join ( dir , 'entry.mjs' ) ;
32- fs . writeFileSync ( entry , imports . join ( '\n' ) + '\n' ) ;
33- return entry ;
40+ return path . join ( dir , 'mod0.mjs' ) ;
3441}
3542
3643function main ( { n, modules } ) {
37- const entry = prepare ( modules ) ;
44+ const entry = prepare ( Number ( modules ) ) ;
3845 const cmd = process . execPath || process . argv [ 0 ] ;
3946 const warmup = 3 ;
4047 const state = { finished : - warmup } ;
0 commit comments