-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
os: improve networkInterfaces performance #22359
Conversation
e7c90b9
to
bb4a589
Compare
bb4a589
to
e625c9d
Compare
LGTM, nice! |
I just pushed another commit that optimizes the algorithm. It is now a much simpler and straight forward as I calculate the number of ones right away and use modulo 2 to validate the entry. New benchmark result:
|
lib/os.js
Outdated
} | ||
|
||
const parts = netmask.split(split); | ||
for (const part of parts) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you are rewriting this for performance, is for...of
as fast as the classic for loop now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracking bug: https://bugs.chromium.org/p/v8/issues/detail?id=8070
lib/os.js
Outdated
return null; | ||
} | ||
} else if (tmp !== groupLength) { | ||
if (binary % 2 !== 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use (binary & 1) !== 0
. Last time I tried the reminder operator was not optimized for this, maybe it is now, don't know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracking bug https://bugs.chromium.org/p/v8/issues/detail?id=8069
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments addressed. The performance is now again a tiny bit improved compared to before by using:
|
This algorithm uses less data transformations and is therefore significantly faster than the one before.
0baa2d7
to
17f4930
Compare
Rebased due to a hiccup with the CI. I only squashed commits that were already reviewed. CI https://ci.nodejs.org/job/node-test-pull-request/16576/ ✔️ |
Still LGTM |
This algorithm uses less data transformations and is therefore significantly faster than the one before. PR-URL: nodejs#22359 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Landed in 9bcb744 🎉 |
This algorithm uses less data transformations and is therefore significantly faster than the one before. PR-URL: #22359 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
This algorithm uses less data transformations and is therefore significantly faster than the one before. PR-URL: #22359 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
This algorithm uses less data transformations and is therefore
significantly faster than the one before.
The main pain point is how the CIDR suffix is calculated. It would
be best to port this to C++ instead of having to do this in JS as all other
transformations are done in C++. But since this improves the
performance already quite a bit it's a good first step.
Performance:
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes