Skip to content

child_process: refactor internal/child_process.js - #11366

Closed
notarseniy wants to merge 1 commit into
nodejs:masterfrom
notarseniy:internal-child-process-fix
Closed

child_process: refactor internal/child_process.js#11366
notarseniy wants to merge 1 commit into
nodejs:masterfrom
notarseniy:internal-child-process-fix

Conversation

@notarseniy

@notarseniynotarseniy commented Feb 14, 2017

Copy link
Copy Markdown
Contributor
  • Prefer === to == where possible
  • Remove condition that will always be false
  • Prefer for-loop statements to forEach where possible for perfomance reasons
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

child_process

@nodejs-github-botnodejs-github-bot added the child_process Issues and PRs related to the child_process subsystem. label Feb 14, 2017
Comment threadlib/internal/child_process.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use var instead of let here for better backportability (let used in this way is still slower at least in v6.x and v4.x).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This suggestion goes for all of the other occurrences below too.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

OK! Is there a guide on code style?

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.

@notarseniymake lint should have reported that issue. make lint is part of make test so if you ran tests, that should have come up as a lint error after the tests all passed. If the linter didn't report it, then there is probably a bug in our custom lint rule.

Comment threadlib/internal/child_process.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure this change is really worth it, the previous conditional is shorter and is equivalent in behavior.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Motivation of this change was this line with 'that-style' condition.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well IMHO that other line could/should be changed to a non-strict equality check. The performance difference probably isn't measurable anymore.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Ok!

Comment threadlib/internal/child_process.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of looking up the value each time, add a temporary variable before the conditional. For example:

conststdio=subprocess.stdio;for(vari=0;i<stdio.length;++i){conststream=stdio[i];// .... keep rest of the code the same}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This suggestion goes for all of the other occurrences below too.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah, sounds good. Will fix this

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Good comment. Will fix.

Comment threadlib/internal/child_process.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why this change? This would change behavior...

@notarseniynotarseniyFeb 14, 2017

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

In previous condition we're handling stdio === null, so this condition never will be executed with stdio === null

@notarseniy
notarseniyforce-pushed the internal-child-process-fix branch from 03eba26 to 0b3efdcCompareFebruary 14, 2017 05:00
@notarseniy

Copy link
Copy Markdown
ContributorAuthor

Commited with fixes of comments.

@Trott

Copy link
Copy Markdown
Member

@mscdex

mscdex commented Feb 14, 2017

Copy link
Copy Markdown
Contributor

More linting issues it seems. Run make jslint locally to find the specifics.

I'm guessing it's due to the duplicate var i; declarations in the two new for-loops.

Comment threadlib/internal/child_process.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This could probably be moved to the top of the function, where the first conditional can take advantage of it.

@notarseniy
notarseniyforce-pushed the internal-child-process-fix branch from 0b3efdc to 9bfcaf4CompareFebruary 14, 2017 12:34
* Prefer === to == where possible
* Remove condition that will always be false
* Prefer for-loop statements to forEach where possible for perfomance reasons
@notarseniy
notarseniyforce-pushed the internal-child-process-fix branch from 9bfcaf4 to efaa7d7CompareFebruary 14, 2017 12:36
@notarseniy

Copy link
Copy Markdown
ContributorAuthor

Recommited with fixes. /cc @Trott@mscdex

@mscdex

Copy link
Copy Markdown
Contributor

@mscdex

Copy link
Copy Markdown
Contributor

CI is green. LGTM.

@notarseniy

Copy link
Copy Markdown
ContributorAuthor

Bump! 😅 What the status of PR? Any other comments or additions?

targos pushed a commit that referenced this pull request Feb 18, 2017
* Prefer === to == where possible
* Remove condition that will always be false
* Prefer for-loop statements to forEach where possible for perfomance reasons
PR-URL: #11366
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
@targos

Copy link
Copy Markdown
Member

@notarseniy I think it has just been forgotten. I went ahead and landed it in 8fc362e. Thanks for the contribution!

@targostargos closed this Feb 18, 2017
@notarseniy

Copy link
Copy Markdown
ContributorAuthor

Thats okay :) Thank you too!

@notarseniy
notarseniy deleted the internal-child-process-fix branch February 18, 2017 19:04
addaleax pushed a commit that referenced this pull request Feb 22, 2017
* Prefer === to == where possible
* Remove condition that will always be false
* Prefer for-loop statements to forEach where possible for perfomance reasons
PR-URL: #11366
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
@italoacasasitaloacasas mentioned this pull request Feb 25, 2017
jasnell pushed a commit that referenced this pull request Mar 7, 2017
* Prefer === to == where possible
* Remove condition that will always be false
* Prefer for-loop statements to forEach where possible for perfomance reasons
PR-URL: #11366
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
jasnell pushed a commit that referenced this pull request Mar 7, 2017
* Prefer === to == where possible
* Remove condition that will always be false
* Prefer for-loop statements to forEach where possible for perfomance reasons
PR-URL: #11366
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
MylesBorins pushed a commit that referenced this pull request Mar 9, 2017
* Prefer === to == where possible
* Remove condition that will always be false
* Prefer for-loop statements to forEach where possible for perfomance reasons
PR-URL: #11366
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
@MylesBorinsMylesBorins mentioned this pull request Mar 9, 2017
MylesBorins pushed a commit that referenced this pull request Mar 9, 2017
* Prefer === to == where possible
* Remove condition that will always be false
* Prefer for-loop statements to forEach where possible for perfomance reasons
PR-URL: #11366
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
@MylesBorinsMylesBorins mentioned this pull request Mar 9, 2017
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

child_processIssues and PRs related to the child_process subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@notarseniy@Trott@mscdex@targos@sam-github@cjihrig@nodejs-github-bot