-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
policy: add startup benchmark and make SRI lazier
PR-URL: #29527 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
1 parent
7be8dde
commit 0ede223
Showing
4 changed files
with
119 additions
and
33 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,51 @@ | ||
// Tests the impact on eager operations required for policies affecting | ||
// general startup, does not test lazy operations | ||
'use strict'; | ||
const common = require('../common.js'); | ||
|
||
const configs = { | ||
n: [1024] | ||
}; | ||
|
||
const options = { | ||
flags: ['--expose-internals'] | ||
}; | ||
|
||
const bench = common.createBenchmark(main, configs, options); | ||
|
||
function main(conf) { | ||
const hash = (str, algo) => { | ||
const hash = require('crypto').createHash(algo); | ||
return hash.update(str).digest('base64'); | ||
}; | ||
const resources = Object.fromEntries( | ||
// Simulate graph of 1k modules | ||
Array.from({ length: 1024 }, (_, i) => { | ||
return [`./_${i}`, { | ||
integrity: `sha256-${hash(`// ./_${i}`, 'sha256')}`, | ||
dependencies: Object.fromEntries(Array.from({ | ||
// Average 3 deps per 4 modules | ||
length: Math.floor((i % 4) / 2) | ||
}, (_, ii) => { | ||
return [`_${ii}`, `./_${i - ii}`]; | ||
})), | ||
}]; | ||
}) | ||
); | ||
const json = JSON.parse(JSON.stringify({ resources }), (_, o) => { | ||
if (o && typeof o === 'object') { | ||
Reflect.setPrototypeOf(o, null); | ||
Object.freeze(o); | ||
} | ||
return o; | ||
}); | ||
const { Manifest } = require('internal/policy/manifest'); | ||
|
||
bench.start(); | ||
|
||
for (let i = 0; i < conf.n; i++) { | ||
new Manifest(json, 'file://benchmark/policy-relative'); | ||
} | ||
|
||
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
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,9 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
|
||
const runBenchmark = require('../common/benchmark'); | ||
|
||
runBenchmark('policy', [ | ||
'n=1', | ||
]); |