FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

lib: prefer optional chaining by avivkeller · Pull Request #55045 · nodejs/node · GitHub

/ node Public

lib: prefer optional chaining - #55045

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
avivkeller:prefer-optional-chaining
Sep 24, 2024
Merged

lib: prefer optional chaining#55045
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
avivkeller:prefer-optional-chaining

Conversation

Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto
  • @nodejs/http
  • @nodejs/loaders
  • @nodejs/net
  • @nodejs/startup
  • @nodejs/streams

nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Sep 21, 2024

lpinca commented Sep 21, 2024

Copy link
Copy Markdown
Member

Why? I won't block, but this is a cosmetic change that does not add any value in my opinion. It only adds noise to git blame.

avivkeller commented Sep 21, 2024
edited
Loading

Copy link
Copy Markdown
Member Author

IIRC optional chaining is slightly faster.

Quick and dirty JSBench shows a ~0.3-1% improvement in ops/sec: https://jsben.ch/znvKH

lpinca commented Sep 21, 2024
edited
Loading

Copy link
Copy Markdown
Member

The performance is the same:

const Benchmark = require('benchmark');

const suite = new Benchmark.Suite();

const testBad = {};

suite.add('Optional chaining', function () {
  let wow;

  if (testBad?.id === '123') {
    wow = 'ok';
  }

  return wow;
});

suite.add('Without optional chaining', function () {
  let wow;

  if (testBad && testBad.id && testBad.id === '123') {
    wow = 'ok';
  }

  return wow;
});

suite.on('cycle', function (event) {
  console.log(event.target.toString());
});

suite.on('complete', function () {
  console.log('Fastest is ' + this.filter('fastest').map('name'));
});

suite.run({ async: true });
$ node index.js 
Optional chaining x 103,663,582 ops/sec ±6.25% (75 runs sampled)
Without optional chaining x 106,320,156 ops/sec ±5.14% (76 runs sampled)
Fastest is Without optional chaining,Optional chaining

Copy link
Copy Markdown
Member Author

ahh interesting. In that case, then yes, this is purely cosmetic, but I still think that using optional chaining is more concise and readable than without, but if it adds too much noise, it's not a needed change, however I'd love to see some other opinions.

panva 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I won't block but i'd say this ought to be accompanied by a linter enforcement. And that's when this will be debated ;)

codecov Bot commented Sep 21, 2024
edited
Loading

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 93.33333% with 5 lines in your changes missing coverage. Please review.

Project coverage is 88.24%. Comparing base (8b8fc53) to head (dbf1046).
Report is 445 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/modules/esm/translators.js 0.00% 2 Missing ⚠️
lib/_tls_wrap.js 50.00% 0 Missing and 1 partial ⚠️
lib/assert.js 66.66% 1 Missing ⚠️
lib/net.js 66.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #55045   +/-   ##
=======================================
  Coverage   88.23%   88.24%           
=======================================
  Files         652      652           
  Lines      183855   183896   +41     
  Branches    35856    35856           
=======================================
+ Hits       162227   162274   +47     
+ Misses      14909    14908    -1     
+ Partials     6719     6714    -5     
Files with missing lines Coverage Δ
lib/_http_agent.js 98.19% <100.00%> (ø)
lib/_http_client.js 97.96% <100.00%> (ø)
lib/_http_common.js 100.00% <100.00%> (ø)
lib/_http_incoming.js 99.33% <100.00%> (ø)
lib/_http_outgoing.js 95.05% <100.00%> (ø)
lib/_http_server.js 96.74% <100.00%> (+0.08%) ⬆️
lib/child_process.js 97.74% <100.00%> (-0.01%) ⬇️
lib/dgram.js 97.31% <100.00%> (ø)
lib/internal/bootstrap/switches/is_main_thread.js 95.91% <100.00%> (ø)
lib/internal/child_process.js 94.72% <100.00%> (ø)
... and 24 more

... and 50 files with indirect coverage changes

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

lgtm

mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 21, 2024
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 21, 2024

Copy link
Copy Markdown
Collaborator

Comment thread test/common/dns.js Outdated

lpinca commented Sep 21, 2024
edited
Loading

Copy link
Copy Markdown
Member

Going forward, has the project's stance on cosmetic changes changed? We've rejected dozens of patches like this in the past. I think that approving some while rejecting others is disrespectful to contributors who have theirs rejected.

avivkeller added the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Sep 21, 2024

anonrig 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Going forward, has the project's stance on cosmetic changes changed?

Once I think about it, I think I agree with @lpinca. This needs to come with a eslint rule.

avivkeller removed the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Sep 21, 2024
avivkeller requested a review from anonrig September 21, 2024 19:41

Copy link
Copy Markdown
Member Author

@anonrig I added a prefer-optional-chaining lint rule. Are you still blocking?

mertcanaltin 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

lgtm

avivkeller added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 23, 2024
avivkeller added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Sep 23, 2024
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 23, 2024

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Member

@anonrig Would you mind re-reviewing or dismissing the request changes, as your concerns were addressed?

avivkeller added the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Sep 24, 2024
atlowChemi added the commit-queue Add this label to land a pull request using GitHub Actions. label Sep 24, 2024
nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Sep 24, 2024
nodejs-github-bot merged commit 574f2dd into nodejs:main Sep 24, 2024

Copy link
Copy Markdown
Collaborator

Landed in 574f2dd

targos pushed a commit that referenced this pull request Oct 4, 2024
PR-URL: #55045
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
aduh95 mentioned this pull request Oct 9, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 outstanding review comments, and a CI started. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.


Back | FazBrowse Home | New Git URL