mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08:00
Speed up creating and aborting signals, adding and removing abort listeners, AbortSignal.any() and AbortSignal.timeout(), and stop the default abort reason from retaining the aborting caller. - Only allocate and dispatch the abort event when the signal has abort listeners, and only allocate the dependent signal list when there are dependent signals. - Track whether an event is trusted with a private field instead of a WeakSet. - Flatten addEventListener() options into locals instead of allocating a normalized options object, only validate the signal option when one is passed, and use the listener flags directly. - Call the EventTarget kNewListener and kRemoveListener implementations directly. V8 does not optimize keyed super property access such as super[kNewListener](). - Initialize the internal slots that AbortSignal.any() adds to its sources up front, and the composite-only slots for composites, so live signals don't change shape. - Give every signal a single WeakRef that is shared by all the composites that follow it, and register each composite and each source once with their cleanup registries instead of registering every (source, composite) pair with an unregister token. Registering with an unregister token is several times more expensive. - Register AbortSignal.timeout() timers through a holder that is emptied when the timer fires, instead of using the signal as an unregister token. - Take positional arguments in AbortSignal's internal constructor instead of destructuring an options object that defaults to kEmptyObject. kEmptyObject is a null-prototype object, which V8 keeps in dictionary mode, so each of those reads was an uncached dictionary miss that cost more than the rest of the constructor. - Create the default abort reason with Error.stackTraceLimit set to 0. Until a captured stack is formatted, V8 keeps the call sites, which retain the receivers and functions of the aborting caller's frames, so a retained signal kept the aborted work alive. Formatting the stack eagerly would fix that but costs several microseconds per abort(). The default AbortError no longer shows where abort() was called; callers that want that can pass their own reason. - Add benchmarks for aborting, adding and removing abort listeners, and AbortSignal.any(). Refs: https://github.com/nodejs/node/issues/66192 Refs: https://github.com/nodejs/node/pull/66265 Assisted-by: claude:opus-5.5 Signed-off-by: Robert Nagy <ronagy@icloud.com> PR-URL: https://github.com/nodejs/node/pull/66789 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>