Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: replace brand checks with identity checks #57341

Merged
merged 1 commit into from
Mar 7, 2025

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Mar 5, 2025

An identity check is always faster than a brand check.

@anonrig anonrig requested a review from jasnell March 5, 2025 21:41
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem. labels Mar 5, 2025
@anonrig anonrig 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 Mar 5, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 5, 2025
@nodejs-github-bot
Copy link
Collaborator

@ljharb
Copy link
Member

ljharb commented Mar 5, 2025

primitives don't have identity, and typeof isn't checking a brand - but terms aside, i'm very surprised that x === undefined is faster than the many-decades-optimized typeof x === 'undefined'. do you have benchmark data that demonstrates that?

Copy link

codecov bot commented Mar 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.19%. Comparing base (8342183) to head (7bc71d9).
Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #57341      +/-   ##
==========================================
- Coverage   90.19%   90.19%   -0.01%     
==========================================
  Files         630      630              
  Lines      185195   185195              
  Branches    36249    36243       -6     
==========================================
- Hits       167036   167033       -3     
- Misses      11132    11140       +8     
+ Partials     7027     7022       -5     
Files with missing lines Coverage Δ
lib/net.js 94.95% <100.00%> (ø)

... and 37 files with indirect coverage changes

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nodejs-github-bot
Copy link
Collaborator

@anonrig
Copy link
Member Author

anonrig commented Mar 6, 2025

primitives don't have identity, and typeof isn't checking a brand - but terms aside, i'm very surprised that x === undefined is faster than the many-decades-optimized typeof x === 'undefined'. do you have benchmark data that demonstrates that?

I don't have any benchmark results to share at the moment. Even if I had, these changes will not move the needle a tiny single bit.

@anonrig anonrig added the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 6, 2025
@ljharb
Copy link
Member

ljharb commented Mar 6, 2025

… then why make the change if it won't move the needle?

@anonrig
Copy link
Member Author

anonrig commented Mar 6, 2025

… then why make the change if it won't move the needle?

For refactor purposes, making the code align with the rest of the codebase, also for readability.

But these are all open to discussion and can change from people to people. So, it's within your right to block if you think this is unnecessary.

No hard feelings :-)

@ljharb
Copy link
Member

ljharb commented Mar 7, 2025

Oh no, there's absolutely no reason to block here :-) if it's the consistent style in the project then that's sufficient reason on its own. I was just asking the question because if there's any performance-motivated change without a benchmark, then it's almost a certainty that the performance will be regressed in the future, so if it's worth making it faster, it's presumably worth keeping it faster.

@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 7, 2025
@nodejs-github-bot nodejs-github-bot merged commit 3a497dc into nodejs:main Mar 7, 2025
72 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 3a497dc

aduh95 pushed a commit that referenced this pull request Mar 9, 2025
PR-URL: #57341
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
aduh95 pushed a commit that referenced this pull request Mar 9, 2025
PR-URL: #57341
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
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. needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants