-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
tls: use for loop instead of forEach #24715
Conversation
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.
This code runs once at the point where this module is required. It'll be a completely imperceptible performance difference. Unrolling this loop altogether would make the performance optimal but doesn't mean we should do that. We should always consider magnitude of any performance improvements.
This change wouldn't cause any bad effect, even may make a bit of better, so why not do so ? |
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.
This makes the code less readable/maintainable for a micro-optimization that is unlikely to have any impact.
🤔Wondering what do you think about the proxiedMethods, these two parts are almost same with each other: |
I'd say make all non-critical loops |
I just don't see any reason to churn on either of these. Both are valid JavaScript that works and changing them will bring no benefit beyond adding another layer to the |
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.
in recent versions of v8, forEach is faster than a loop in cases like this. plus the loop is more readable.
I think for pratical reasons, all for variants perform the same (https://jsperf.com/for-vs-foreach/293). I came to prefer |
Thanks all of you to explain for this, let me understand a lot. If no one would like to talk more about this, please feel free to close it. |
I'll close this out, but thanks for the PR. |
Using native
for loop
instead offorEach
may make the performance a bit of better ?On the other hand, it's for consistency with proxiedMethods
Refs: #11582
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes