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

util: remove duplicate code in format #15098

Closed

Conversation

apapirovski
Copy link
Contributor

@apapirovski apapirovski commented Aug 30, 2017

util.format contained an identical if statement within each case of switch. Moved it before the switch statement for cleaner code and better performance. Passes all the current tests, plus here are the benchmark results (20 sets on old, 20 sets on new):

util/format.js type="no-replace" n=1000000      0.62 %            4.906062e-01
util/format.js type="number" n=1000000          4.80 %        *** 6.199638e-19
util/format.js type="object" n=1000000          3.07 %        *** 2.491792e-08
util/format.js type="string" n=1000000          6.60 %        *** 2.331874e-08
util/format.js type="unknown" n=1000000         0.68 %            2.174034e-01
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

util

util.format contains an idential if statement within each branch
of switch. Move it before the switch statement for cleaner code
and better performance.
@nodejs-github-bot nodejs-github-bot added the util Issues and PRs related to the built-in util module. label Aug 30, 2017
Copy link
Member

@targos targos left a comment

Choose a reason for hiding this comment

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

Thank you. LGTM.

@vsemozhetbyt
Copy link
Contributor

@refack refack self-assigned this Aug 30, 2017
@BridgeAR
Copy link
Member

I think this does not need the typical 48 hours.

@evanlucas
Copy link
Contributor

@BridgeAR generally, only doc updates can get a pass for the 48 rule...

@BridgeAR
Copy link
Member

@evanlucas oh, alright. I somehow remembered it would also be trivial fixes and the code change seems pretty simple to me and there were already a lot of looking goods. That is why I suggested it. Thanks for the info!

@BridgeAR
Copy link
Member

Hm, even though the docs say otherwise. I cite https://github.com/nodejs/node/blob/master/COLLABORATOR_GUIDE.md#accepting-modifications

Trivial changes (e.g. those which fix minor bugs or improve performance without affecting API or causing other wide-reaching impact) may be landed after a shorter delay.

@evanlucas
Copy link
Contributor

@BridgeAR ah fair point. My bad :]

@BridgeAR
Copy link
Member

BridgeAR commented Aug 30, 2017

Landed in 365c245 after asking @evanlucas about his OK again.

@BridgeAR BridgeAR closed this Aug 30, 2017
BridgeAR pushed a commit that referenced this pull request Aug 30, 2017
util.format contains an idential if statement within each branch
of switch. Move it before the switch statement for cleaner code
and better performance.

PR-URL: #15098
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
@apapirovski apapirovski deleted the patch-util-format-cleanup branch September 4, 2017 14:38
addaleax pushed a commit to addaleax/ayo that referenced this pull request Sep 5, 2017
util.format contains an idential if statement within each branch
of switch. Move it before the switch statement for cleaner code
and better performance.

PR-URL: nodejs/node#15098
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
MylesBorins pushed a commit that referenced this pull request Sep 10, 2017
util.format contains an idential if statement within each branch
of switch. Move it before the switch statement for cleaner code
and better performance.

PR-URL: #15098
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Sep 10, 2017
MylesBorins pushed a commit that referenced this pull request Sep 12, 2017
util.format contains an idential if statement within each branch
of switch. Move it before the switch statement for cleaner code
and better performance.

PR-URL: #15098
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
@MylesBorins
Copy link
Contributor

Should this be backported to v6.x-staging? If yes please follow the guide and raise a backport PR, if no let me know or add the dont-land-on label.

@apapirovski
Copy link
Contributor Author

@MylesBorins it could be (easily) since this was quite a minor change but there are commits between where this landed and where 6.x is at. Not sure what the general policy is around back-porting.

Specifically: 4191962 and a46c43d

I'm guessing the latter might be out of scope for backporting since it introduces new functionality but the former is just a performance change.

@refack refack removed their assignment Oct 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.