Skip to content

stream: refactor unnecessary optional chaining away#64253

Open
aduh95 wants to merge 1 commit into
nodejs:mainfrom
aduh95:optional-optional-chaining
Open

stream: refactor unnecessary optional chaining away#64253
aduh95 wants to merge 1 commit into
nodejs:mainfrom
aduh95:optional-optional-chaining

Conversation

@aduh95

@aduh95 aduh95 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

According to https://adventures.nodeland.dev/archive/noop-functions-vs-optional-chaining-a-performance/, we should shave a few cycles
Most of those have become unnecessary since #63876

Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. web streams labels Jul 2, 2026
@aduh95

aduh95 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1880/
Benchmark GHA: https://github.com/nodejs/node/actions/runs/28578934840

Results
                                                                       confidence improvement accuracy (*)   (**)  (***)
webstreams/creation.js kind='ReadableStream.tee' n=50000                              -0.25 %       ±0.34% ±0.45% ±0.58%
webstreams/creation.js kind='ReadableStream' n=50000                                   3.46 %       ±4.75% ±6.33% ±8.23%
webstreams/creation.js kind='ReadableStreamBYOBReader' n=50000                        -0.58 %       ±0.99% ±1.32% ±1.72%
webstreams/creation.js kind='ReadableStreamDefaultReader' n=50000               *     -1.18 %       ±0.93% ±1.24% ±1.62%
webstreams/creation.js kind='TransformStream' n=50000                                 -0.11 %       ±0.89% ±1.18% ±1.54%
webstreams/creation.js kind='WritableStream' n=50000                                  -0.30 %       ±1.29% ±1.72% ±2.23%
webstreams/js_transfer.js n=10000 payload='ReadableStream'                            -0.02 %       ±0.60% ±0.80% ±1.04%
webstreams/js_transfer.js n=10000 payload='TransformStream'                           -0.29 %       ±0.48% ±0.63% ±0.83%
webstreams/js_transfer.js n=10000 payload='WritableStream'                            -0.06 %       ±0.58% ±0.77% ±1.01%
webstreams/pipe-to.js highWaterMarkW=1024 highWaterMarkR=1024 n=500000                 0.06 %       ±1.06% ±1.41% ±1.83%
webstreams/pipe-to.js highWaterMarkW=1024 highWaterMarkR=2048 n=500000                -0.58 %       ±1.05% ±1.40% ±1.83%
webstreams/pipe-to.js highWaterMarkW=1024 highWaterMarkR=4096 n=500000                 0.38 %       ±1.38% ±1.84% ±2.40%
webstreams/pipe-to.js highWaterMarkW=1024 highWaterMarkR=512 n=500000                  0.04 %       ±0.93% ±1.24% ±1.62%
webstreams/pipe-to.js highWaterMarkW=2048 highWaterMarkR=1024 n=500000                -0.68 %       ±0.96% ±1.28% ±1.67%
webstreams/pipe-to.js highWaterMarkW=2048 highWaterMarkR=2048 n=500000                -0.31 %       ±1.16% ±1.55% ±2.01%
webstreams/pipe-to.js highWaterMarkW=2048 highWaterMarkR=4096 n=500000                 0.02 %       ±1.17% ±1.56% ±2.03%
webstreams/pipe-to.js highWaterMarkW=2048 highWaterMarkR=512 n=500000                  0.42 %       ±1.17% ±1.56% ±2.04%
webstreams/pipe-to.js highWaterMarkW=4096 highWaterMarkR=1024 n=500000                -0.03 %       ±1.15% ±1.52% ±1.99%
webstreams/pipe-to.js highWaterMarkW=4096 highWaterMarkR=2048 n=500000                -0.10 %       ±1.16% ±1.55% ±2.02%
webstreams/pipe-to.js highWaterMarkW=4096 highWaterMarkR=4096 n=500000                 0.14 %       ±0.94% ±1.26% ±1.64%
webstreams/pipe-to.js highWaterMarkW=4096 highWaterMarkR=512 n=500000           *      1.06 %       ±0.99% ±1.32% ±1.72%
webstreams/pipe-to.js highWaterMarkW=512 highWaterMarkR=1024 n=500000                  0.06 %       ±1.15% ±1.53% ±1.99%
webstreams/pipe-to.js highWaterMarkW=512 highWaterMarkR=2048 n=500000                 -0.70 %       ±0.93% ±1.24% ±1.61%
webstreams/pipe-to.js highWaterMarkW=512 highWaterMarkR=4096 n=500000                  0.46 %       ±1.20% ±1.59% ±2.08%
webstreams/pipe-to.js highWaterMarkW=512 highWaterMarkR=512 n=500000                  -0.61 %       ±1.19% ±1.59% ±2.07%
webstreams/readable-async-iterator.js n=100000                                         0.80 %       ±1.40% ±1.87% ±2.43%
webstreams/readable-read-buffered.js bufferSize=1 n=100000                             0.56 %       ±2.32% ±3.09% ±4.03%
webstreams/readable-read-buffered.js bufferSize=10 n=100000                            2.84 %       ±3.64% ±4.84% ±6.30%
webstreams/readable-read-buffered.js bufferSize=100 n=100000                          -1.58 %       ±3.20% ±4.26% ±5.54%
webstreams/readable-read-buffered.js bufferSize=1000 n=100000                         -0.50 %       ±3.21% ±4.27% ±5.57%
webstreams/readable-read.js type='byob' n=100000                                      -0.24 %       ±0.88% ±1.17% ±1.53%
webstreams/readable-read.js type='normal' n=100000                                     0.06 %       ±2.15% ±2.87% ±3.74%

Be aware that when doing many comparisons the risk of a false-positive
result increases. In this case, there are 32 comparisons, you can thus
expect the following amount of false-positive results:
  1.60 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.32 false positives, when considering a   1% risk acceptance (**, ***),
  0.03 false positives, when considering a 0.1% risk acceptance (***)

@aduh95 aduh95 requested a review from mcollina July 2, 2026 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. web streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants