-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vm: don't set host-defined options when it's not necessary
This makes it possile to hit the in-isolate compilation cache when host-defined options are not necessary.
- Loading branch information
1 parent
1dc0667
commit 78c5217
Showing
3 changed files
with
60 additions
and
13 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,35 @@ | ||
'use strict'; | ||
|
||
// This benchmarks compiling scripts that hit the in-isolate compilation | ||
// cache (by having the same source). | ||
const common = require('../common.js'); | ||
const fs = require('fs'); | ||
const vm = require('vm'); | ||
const fixtures = require('../../test/common/fixtures.js'); | ||
const scriptPath = fixtures.path('snapshot', 'typescript.js'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
type: ['with-dynamic-import-callback', 'without-dynamic-import-callback'], | ||
n: [100], | ||
}); | ||
|
||
const scriptSource = fs.readFileSync(scriptPath, 'utf8'); | ||
|
||
function main({ n, type }) { | ||
let script; | ||
bench.start(); | ||
let options = {}; | ||
switch (type) { | ||
case 'with-dynamic-import-callback': | ||
// Use a dummy callback for now until we really need to benchmark it. | ||
options.importModuleDynamically = async() => {}; | ||
break; | ||
case 'without-dynamic-import-callback': | ||
break; | ||
} | ||
for (let i = 0; i < n; i++) { | ||
script = new vm.Script(scriptSource, options); | ||
} | ||
bench.end(n); | ||
script.runInThisContext(); | ||
} |
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