X Tutup
The Wayback Machine - https://web.archive.org/web/20220409062951/https://github.com/nodejs/node/pull/42573
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

tools: enable ESLint no-var rule in lib #42573

Closed
wants to merge 2 commits into from
Closed

tools: enable ESLint no-var rule in lib #42573

wants to merge 2 commits into from

Conversation

Copy link
Member

@Trott Trott commented Apr 2, 2022

First commit is from #42563. Other two commits change the rest of the files in lib and enables the ESLint rule.

@Trott Trott added the commit-queue-rebase label Apr 2, 2022
@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Apr 2, 2022

@nodejs-github-bot nodejs-github-bot added lib / src needs-ci labels Apr 2, 2022
lib/internal/async_hooks.js Show resolved Hide resolved
lib/internal/async_hooks.js Show resolved Hide resolved
// Using var here instead of let because "for (var ...)" is faster than let.
// Refs: https://github.com/nodejs/node/pull/30380#issuecomment-552948364
for (var i = 0; i < active_hooks.array.length; i++) {
for (let i = 0; i < active_hooks.array.length; i++) {
Copy link
Member

@mcollina mcollina Apr 2, 2022

Choose a reason for hiding this comment

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

I would restrain from making this change unless we have ample evidence that it's as fast as.

Copy link
Member

@RaisinTen RaisinTen Apr 2, 2022

Choose a reason for hiding this comment

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

@mcollina the for(var...) loop in os.networkInterfaces() was changed to for(let...) in #42563 and I ran a benchmark for that in #42563 (comment) and there was no significant perf regression. Could the results be different for these for loops?

Copy link
Member

@mcollina mcollina Apr 2, 2022

Choose a reason for hiding this comment

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

This is one of the hottest loops of the whole Node.js. Keeping a var here does not hurt anybody - most contributors should not even come to this file. Let this be and avoid future problems.

Copy link
Member

@VoltrexMaster VoltrexMaster Apr 3, 2022

Choose a reason for hiding this comment

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

Better to run a benchmark for this PR as well to find out if it's as fast or not. The performance edge cases (no matter the condition, hot or cold paths) were rather fixed in V8 years ago, as also seen in the mentioned PR (#42563).

Copy link
Member Author

@Trott Trott Apr 3, 2022

Choose a reason for hiding this comment

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

I'll use comments to disable linting for the ones @mcollina has flagged, and then we can do benchmarks on them or leave them as appropriate without holding up landing the rest of this.

// Using var here instead of let because "for (var ...)" is faster than let.
// Refs: https://github.com/nodejs/node/pull/30380#issuecomment-552948364
for (var i = 0; i < active_hooks.array.length; i++) {
for (let i = 0; i < active_hooks.array.length; i++) {
Copy link
Member

@mcollina mcollina Apr 2, 2022

Choose a reason for hiding this comment

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

I would restrain from making this change unless we have ample evidence that it's as fast as.

@@ -171,7 +171,7 @@ class JSStreamSocket extends Socket {

this.stream.cork();
// Use `var` over `let` for performance optimization.
for (var i = 0; i < bufs.length; ++i)
for (let i = 0; i < bufs.length; ++i)
Copy link
Member

@mcollina mcollina Apr 2, 2022

Choose a reason for hiding this comment

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

I would restrain from making this change unless we have ample evidence that it's as fast as.

@Trott
Copy link
Member Author

@Trott Trott commented Apr 3, 2022

@mcollina I've reverted the three loops you flagged and instead disabled the lint rule for those lines. PTAL. Thanks!

Copy link
Member

@mcollina mcollina left a comment

lgtm

@marsonya marsonya added the request-ci label Apr 4, 2022
@github-actions github-actions bot removed the request-ci label Apr 4, 2022
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Apr 4, 2022

@Trott Trott added the commit-queue label Apr 4, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue label Apr 4, 2022
@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Apr 4, 2022

Landed in aed18df...b07894d

nodejs-github-bot added a commit that referenced this issue Apr 4, 2022
PR-URL: #42573
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
nodejs-github-bot added a commit that referenced this issue Apr 4, 2022
PR-URL: #42573
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
@Trott Trott deleted the no-var branch Apr 4, 2022
juanarbol added a commit to juanarbol/node that referenced this issue Apr 5, 2022
PR-URL: nodejs#42573
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
juanarbol added a commit to juanarbol/node that referenced this issue Apr 5, 2022
PR-URL: nodejs#42573
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
@juanarbol juanarbol mentioned this pull request Apr 5, 2022
@juanarbol juanarbol mentioned this pull request Apr 5, 2022
juanarbol added a commit that referenced this issue Apr 6, 2022
PR-URL: #42573
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
juanarbol added a commit that referenced this issue Apr 6, 2022
PR-URL: #42573
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commit-queue-rebase lib / src needs-ci
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants
X Tutup