Skip to content

stream: refactor unnecessary optional chaining away#64253

Merged
aduh95 merged 2 commits into
nodejs:mainfrom
aduh95:optional-optional-chaining
Jul 4, 2026
Merged

stream: refactor unnecessary optional chaining away#64253
aduh95 merged 2 commits 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
@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Jul 2, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 2, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Unlikely that would matter here in practice.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@aduh95 aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 2, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Jul 4, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator
Commit Queue failed
- Loading data for nodejs/node/pull/64253
✔  Done loading data for nodejs/node/pull/64253
----------------------------------- PR info ------------------------------------
Title      stream: refactor unnecessary optional chaining away (#64253)
   ⚠  Could not retrieve the email or name of the PR author's from user's GitHub profile!
Branch     aduh95:optional-optional-chaining -> nodejs:main
Labels     author ready, needs-ci, web streams
Commits    1
 - stream: refactor unnecessary optional chaining away
Committers 1
 - Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/64253
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/64253
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Thu, 02 Jul 2026 09:09:58 GMT
   ✔  Approvals: 4
   ✔  - Yagiz Nizipli (@anonrig) (TSC): https://github.com/nodejs/node/pull/64253#pullrequestreview-4618774049
   ✔  - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/64253#pullrequestreview-4620379258
   ✔  - Luigi Pinca (@lpinca): https://github.com/nodejs/node/pull/64253#pullrequestreview-4627711659
   ✔  - Gürgün Dayıoğlu (@gurgunday): https://github.com/nodejs/node/pull/64253#pullrequestreview-4627959894
   ✔  Last GitHub CI successful
   ℹ  Last Benchmark CI on 2026-07-02T09:14:12Z: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1880/
   ℹ  Last Full PR CI on 2026-07-02T18:53:13Z: https://ci.nodejs.org/job/node-test-pull-request/74520/
- Querying data for job/node-test-pull-request/74520/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  No git cherry-pick in progress
   ✔  No git am in progress
   ✔  No git rebase in progress
--------------------------------------------------------------------------------
- Bringing origin/main up to date...
From https://github.com/nodejs/node
 * branch                  main       -> FETCH_HEAD
   e76c573e45..51dbfd607c  main       -> origin/main
✔  origin/main is now up-to-date
main is out of sync with origin/main. Mismatched commits:
 - 8f28dd8c6c doc: fix typo in examples
 - 51dbfd607c doc: fix typo in examples
--------------------------------------------------------------------------------
HEAD is now at 51dbfd607c doc: fix typo in examples
   ✔  Reset to origin/main
- Downloading patch for 64253
From https://github.com/nodejs/node
 * branch                  refs/pull/64253/merge -> FETCH_HEAD
✔  Fetched commits as 8410a918eaef..b1a7ae3ab4df
--------------------------------------------------------------------------------
Auto-merging lib/internal/webstreams/readablestream.js
Auto-merging lib/internal/webstreams/transformstream.js
CONFLICT (content): Merge conflict in lib/internal/webstreams/transformstream.js
Auto-merging lib/internal/webstreams/writablestream.js
error: could not apply b1a7ae3ab4... stream: refactor unnecessary optional chaining away
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
   ✘  Failed to apply patches
https://github.com/nodejs/node/actions/runs/28702199076

@aduh95 aduh95 merged commit 3ee5f31 into nodejs:main Jul 4, 2026
30 checks passed
@aduh95

aduh95 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Landed in 3ee5f31

@aduh95 aduh95 deleted the optional-optional-chaining branch July 4, 2026 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-failed An error occurred while landing this pull request using GitHub Actions. needs-ci PRs that need a full CI run. web streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants