Files
node/lib/internal
James M Snell 153ec89621 stream: make stream/iter from() cancellation waits cheaper
To stay cancellable while a source is pending, from() waits for every
value of an async source through waitForNormalization(). For each value
it created a PromiseWithResolvers(), raced it against the value with
SafePromiseRace(), which wraps both in new promises, and ran an async
function with try/finally. This was the largest per-batch cost of
normalizing an async source.

Wait with a single promise and a single reaction on the value instead,
and reject that promise directly on cancellation. The outcome is
unchanged: the value's result, its rejection, or the cancellation
reason, whichever comes first, and the cancellation reason if the
normalization was cancelled by the time the value fulfills.

With an async generator yielding 16-byte chunks, pipeTo() is about
1.7x faster and iterating from() about 1.75x faster.

Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66648
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-10-15 13:26:52 +00:00
..
2026-10-05 16:47:38 +00:00
…
…
2026-10-15 00:52:34 +00:00
2026-10-15 00:52:34 +00:00
…
…
…
2026-10-15 07:53:03 +00:00
…
…
…
…
…
2026-10-15 00:52:34 +00:00
…
…
…
…
2026-10-05 05:47:29 +00:00
…
…
…
…
…
…

Internal Modules

The modules located in lib/internal directory are exclusively meant for internal usage within the Node.js core. They are not intended to be accessed via user modules require(). These modules may change at any point in time. Relying on these internal modules outside the core is not supported and can lead to unpredictable behavior.

In certain scenarios, accessing these internal modules for debugging or experimental purposes might be necessary. Node.js provides the --expose-internals flag to expose these modules to userland code. This flag only exists to assist Node.js maintainers with debugging internals. It is not meant for use outside the project.