-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf_hooks: reducing overhead of performance observer entry list
PR-URL: #50008 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
- Loading branch information
Showing
2 changed files
with
64 additions
and
16 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,49 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const common = require('../common.js'); | ||
|
||
const { | ||
PerformanceObserver, | ||
performance, | ||
} = require('perf_hooks'); | ||
|
||
function randomFn() { | ||
return Math.random(); | ||
} | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e5], | ||
pending: [1, 10], | ||
}, { | ||
options: ['--expose-internals'], | ||
}); | ||
|
||
let _result; | ||
|
||
function fillQueue(timerfied, pending) { | ||
for (let i = 0; i < pending; i++) { | ||
_result = timerfied(); | ||
} | ||
// Avoid V8 deadcode (elimination) | ||
assert.ok(_result); | ||
} | ||
|
||
function main({ n, pending }) { | ||
const timerfied = performance.timerify(randomFn); | ||
|
||
let count = 0; | ||
const obs = new PerformanceObserver((entries) => { | ||
count += entries.getEntries().length; | ||
|
||
if (count >= n) { | ||
bench.end(count); | ||
} else { | ||
fillQueue(timerfied, pending); | ||
} | ||
}); | ||
obs.observe({ entryTypes: ['function'], buffered: true }); | ||
|
||
bench.start(); | ||
fillQueue(timerfied, pending); | ||
} |
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