mirror of https://github.com/nodejs/node.git
Revert "perf_hooks: make PerformanceObserver an AsyncResource"
This reverts commit 009e41826f
.
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] https://github.com/nodejs/node/pull/18789
Co-Authored-By: ZauberNerd <zaubernerd@zaubernerd.de>
PR-URL: https://github.com/nodejs/node/pull/36343
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
pull/36343/head
parent
c53ba1f618
commit
1ea4b83912
|
@ -52,7 +52,6 @@ const {
|
|||
NODE_PERFORMANCE_MILESTONE_ENVIRONMENT
|
||||
} = constants;
|
||||
|
||||
const { AsyncResource } = require('async_hooks');
|
||||
const L = require('internal/linkedlist');
|
||||
const kInspect = require('internal/util').customInspectSymbol;
|
||||
|
||||
|
@ -340,12 +339,11 @@ class PerformanceObserverEntryList {
|
|||
}
|
||||
}
|
||||
|
||||
class PerformanceObserver extends AsyncResource {
|
||||
class PerformanceObserver {
|
||||
constructor(callback) {
|
||||
if (typeof callback !== 'function') {
|
||||
throw new ERR_INVALID_CALLBACK(callback);
|
||||
}
|
||||
super('PerformanceObserver');
|
||||
ObjectDefineProperties(this, {
|
||||
[kTypes]: {
|
||||
enumerable: false,
|
||||
|
@ -553,10 +551,7 @@ function getObserversList(type) {
|
|||
|
||||
function doNotify(observer) {
|
||||
observer[kQueued] = false;
|
||||
observer.runInAsyncScope(observer[kCallback],
|
||||
observer,
|
||||
observer[kBuffer],
|
||||
observer);
|
||||
observer[kCallback](observer[kBuffer], observer);
|
||||
observer[kBuffer][kEntries] = [];
|
||||
L.init(observer[kBuffer][kEntries]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue