Skip to content

Commit f368d69

Browse files
nicstangetargos
authored andcommitted
Revert "perf_hooks: make PerformanceObserver an AsyncResource"
This reverts commit 009e418. AFAIU the discussion at [1], PerformanceObserver had been made to inherit from AsyncResource more or less as a band-aid in lack of a better async_context candidate to invoke it in. In order to enable access to AsyncLocalStores from PerformanceObservers invoked synchronously through e.g. measure() or mark(), the current async_context, if any, should be retained. Note that this is a breaking change, but - as has been commented at [1], PerformanceObserver being derived from AsyncResource is a "minor divergence from the spec" anyway, - to my knowledge this is an internal implementation detail which has never been documented and - I can't think of a good reason why existing PerformanceObserver implementations would possibly rely on it. OTOH, it's probably worthwhile to not potentially invoke before() and after() async_hooks for each and every PerformanceObserver notification. [1] #18789 Co-Authored-By: ZauberNerd <zaubernerd@zaubernerd.de> PR-URL: #36343 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent e2ced0d commit f368d69

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

lib/perf_hooks.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ const {
5252
NODE_PERFORMANCE_MILESTONE_ENVIRONMENT
5353
} = constants;
5454

55-
const { AsyncResource } = require('async_hooks');
5655
const L = require('internal/linkedlist');
5756
const kInspect = require('internal/util').customInspectSymbol;
5857

@@ -340,12 +339,11 @@ class PerformanceObserverEntryList {
340339
}
341340
}
342341

343-
class PerformanceObserver extends AsyncResource {
342+
class PerformanceObserver {
344343
constructor(callback) {
345344
if (typeof callback !== 'function') {
346345
throw new ERR_INVALID_CALLBACK(callback);
347346
}
348-
super('PerformanceObserver');
349347
ObjectDefineProperties(this, {
350348
[kTypes]: {
351349
enumerable: false,
@@ -553,10 +551,7 @@ function getObserversList(type) {
553551

554552
function doNotify(observer) {
555553
observer[kQueued] = false;
556-
observer.runInAsyncScope(observer[kCallback],
557-
observer,
558-
observer[kBuffer],
559-
observer);
554+
observer[kCallback](observer[kBuffer], observer);
560555
observer[kBuffer][kEntries] = [];
561556
L.init(observer[kBuffer][kEntries]);
562557
}

0 commit comments

Comments
 (0)