mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
perf_hooks: simplify perf_hooks
Remove the `performance.getEntries()` and `performance.clear*()` variants and eliminate the accumulation of the global timeline entries. The design of this particular bit of the API is a memory leak and performance footgun. The `PerformanceObserver` API is a better approach to consuming the data in a more transient way. PR-URL: https://github.com/nodejs/node/pull/19563 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
1 parent
d54f651910
commit
2ec6995555
9 files changed
+38
-320
No files matched your search
@@ -11,9 +11,6 @@ const {
|
||||
{
|
||||
// Intentional non-op. Do not wrap in common.mustCall();
|
||||
const n = performance.timerify(() => {});
|
||||
n();
|
||||
const entries = performance.getEntriesByType('function');
|
||||
assert.strictEqual(entries.length, 0);
|
||||
|
||||
const obs = new PerformanceObserver(common.mustCall((list) => {
|
||||
const entries = list.getEntries();
|
||||
@@ -24,7 +21,6 @@ const {
|
||||
assert.strictEqual(typeof entry.duration, 'number');
|
||||
assert.strictEqual(typeof entry.startTime, 'number');
|
||||
obs.disconnect();
|
||||
performance.clearFunctions();
|
||||
}));
|
||||
obs.observe({ entryTypes: ['function'] });
|
||||
n();
|
||||
@@ -39,17 +35,12 @@ const {
|
||||
throw new Error('test');
|
||||
});
|
||||
assert.throws(() => n(), /^Error: test$/);
|
||||
const entries = performance.getEntriesByType('function');
|
||||
assert.strictEqual(entries.length, 0);
|
||||
obs.disconnect();
|
||||
}
|
||||
|
||||
{
|
||||
class N {}
|
||||
const n = performance.timerify(N);
|
||||
new n();
|
||||
const entries = performance.getEntriesByType('function');
|
||||
assert.strictEqual(entries.length, 0);
|
||||
|
||||
const obs = new PerformanceObserver(common.mustCall((list) => {
|
||||
const entries = list.getEntries();
|
||||
@@ -62,7 +53,6 @@ const {
|
||||
assert.strictEqual(typeof entry.duration, 'number');
|
||||
assert.strictEqual(typeof entry.startTime, 'number');
|
||||
obs.disconnect();
|
||||
performance.clearFunctions();
|
||||
}));
|
||||
obs.observe({ entryTypes: ['function'] });
|
||||
|
||||
|
||||
Reference in new issue
Block a user