GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — util: improve util.format performance by evanlucas · Pull Request #5360 · nodejs/node

Conversation

@evanlucas

@evanlucas evanlucas commented Feb 22, 2016

Copy link
Copy Markdown
Contributor

By manually copying arguments and breaking the try/catch out, we are able to improve the performance of util.format by 20-100% (depending on the types).

Also includes a util.format benchmark.

The numbers:

running ./node
util/format.js
running ./node_before
util/format.js

util/format.js n=1000000 type=string: ./node: 7866600 ./node_before: 1705900 ... 361.13%
util/format.js n=1000000 type=number: ./node: 7718000 ./node_before: 1778900 ... 333.87%
util/format.js n=1000000 type=object: ./node: 1811800 ./node_before: 800160 .... 126.43%
util/format.js n=1000000 type=unknown: ./node: 13045000 ./node_before: 2650300 . 392.22%
util/format.js n=1000000 type=no-replace: ./node: 1541500 ./node_before: 956760 . 61.11%

EDIT: I updated the numbers after rebasing on master and with @mscdex's changes included as well.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kewang and 19h reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@evanlucas evanlucas added util Issues and PRs related to the built-in util module. benchmark Issues and PRs related to Node.js benchmarks and benchmarking infrastructure. performance Issues and PRs related to the performance of Node.js. labels Feb 22, 2016
@evanlucas

evanlucas commented Feb 22, 2016

Copy link
Copy Markdown
Contributor Author

CI: https://ci.nodejs.org/job/node-test-pull-request/1716/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Feb 22, 2016
View reviewed changes
Comment thread lib/util.js Outdated

@mscdex mscdex Feb 22, 2016

Copy link
Copy Markdown
Contributor

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.

Use var here until v8 can optimize let better.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@evanlucas
evanlucas force-pushed the utilformatbench branch from 447e7f1 to 88039b9 Compare February 22, 2016 09:15
mscdex
mscdex reviewed Feb 22, 2016
View reviewed changes
Comment thread lib/util.js Outdated

@mscdex mscdex Feb 22, 2016

Copy link
Copy Markdown
Contributor

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.

Sorry, you'll also need to move the var i declaration out and above and change var i = 1; a few lines below to i = 1 to avoid a linter error.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@evanlucas evanlucas Feb 22, 2016

Copy link
Copy Markdown
Contributor Author

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.

yep, just noticed that locally. Thanks

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@evanlucas
evanlucas force-pushed the utilformatbench branch from 88039b9 to 429ad25 Compare February 22, 2016 09:27
@mscdex

mscdex commented Feb 22, 2016

Copy link
Copy Markdown
Contributor

For bonus points, you can change

for (var x = args[i]; i < len; x = args[++i]) {

to

while (i < len) {
  const x = args[i++];

to avoid an eager deopt due to potential out of bounds access on args.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@evanlucas
evanlucas force-pushed the utilformatbench branch 2 times, most recently from 7a00928 to 91fc8b4 Compare February 22, 2016 09:39
@evanlucas

evanlucas commented Feb 22, 2016

Copy link
Copy Markdown
Contributor Author

Ah, totally missed the case where f is not a string. Added a benchmark and updated for that as well

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Feb 22, 2016
View reviewed changes
Comment thread lib/util.js Outdated

@mscdex mscdex Feb 22, 2016

Copy link
Copy Markdown
Contributor

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.

String(f) here can probably just be replaced with just f since it should already be a string at that point.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@evanlucas

evanlucas commented Feb 22, 2016

Copy link
Copy Markdown
Contributor Author

ooo good catch

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@evanlucas
evanlucas force-pushed the utilformatbench branch from 91fc8b4 to 6fd10fe Compare February 22, 2016 09:46
@mscdex

mscdex commented Feb 22, 2016

Copy link
Copy Markdown
Contributor

CI again: https://ci.nodejs.org/job/node-test-pull-request/1718/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mscdex

mscdex commented Feb 22, 2016

Copy link
Copy Markdown
Contributor

Just for fun I replaced the regexp + replace function with a simple loop and improved performance an additional 60-200% in the benchmarks included (and no change in the no-replace case) in this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@evanlucas

evanlucas commented Feb 22, 2016

Copy link
Copy Markdown
Contributor Author

wow, nice

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell jasnell added the lts-watch-v4.x label Mar 2, 2016
@jasnell

jasnell commented Mar 2, 2016

Copy link
Copy Markdown
Member

Marking this LTS watch but I'd rather this sit for a bit before getting pulled back.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Mar 2, 2016

Copy link
Copy Markdown
Member

LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@evanlucas
evanlucas force-pushed the utilformatbench branch from 774a86e to fe2996a Compare March 4, 2016 22:55
@evanlucas

evanlucas commented Mar 4, 2016

Copy link
Copy Markdown
Contributor Author

Running CI again: https://ci.nodejs.org/job/node-test-pull-request/1851/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

evanlucas and others added 3 commits March 4, 2016 17:27
@evanlucas
benchmark: add util.format benchmark
735e0df
PR-URL: nodejs#5360
Reviewed-By: James M Snell <[email protected]>
@evanlucas
util: improve util.format performance
8d72b0d
By manually copying arguments and breaking the try/catch out, we are
able to improve the performance of util.format by 20-100% (depending on
the types).

PR-URL: nodejs#5360
Reviewed-By: James M Snell <[email protected]>
@mscdex @evanlucas
util: improve format() performance further
c490b8b
Replacing the regexp and replace function with a loop improves
performance by ~60-200%.

PR-URL: nodejs#5360
Reviewed-By: James M Snell <[email protected]>
@evanlucas
evanlucas force-pushed the utilformatbench branch from fe2996a to c490b8b Compare March 4, 2016 23:28
@evanlucas evanlucas closed this Mar 4, 2016
@evanlucas
evanlucas deleted the utilformatbench branch March 4, 2016 23:28
@evanlucas
evanlucas merged commit c490b8b into nodejs:master Mar 4, 2016
@MylesBorins

MylesBorins commented May 17, 2016

Copy link
Copy Markdown
Contributor

@jasnell would you want to include this in a future lts?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented May 17, 2016

Copy link
Copy Markdown
Member

I believe so yes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MylesBorins

MylesBorins commented Jul 1, 2016

Copy link
Copy Markdown
Contributor

@jasnell / @nodejs/lts how much longer to we want this to live before backporting?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Jul 1, 2016

Copy link
Copy Markdown
Member

I haven't heard of any regressions. We may be good on this one
On Jun 30, 2016 5:11 PM, "Myles Borins" [email protected] wrote:

@jasnell https://github.com/jasnell / @nodejs/lts
https://github.com/orgs/nodejs/teams/lts how much longer to we want
this to live before backporting?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#5360 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AAa2eVV5PJs-GWjQjX7nl55qNJMiSNYGks5qRFtAgaJpZM4HfWa3
.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrasq andrasq mentioned this pull request Jul 11, 2016
util: possible way to speed up util.format() #5285
Closed
MylesBorins pushed a commit that referenced this pull request Jul 11, 2016
@evanlucas Myles Borins
util: improve util.format performance
7975137
By manually copying arguments and breaking the try/catch out, we are
able to improve the performance of util.format by 20-100% (depending on
the types).

PR-URL: #5360
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jul 11, 2016
@mscdex Myles Borins
util: improve format() performance further
a7a623b
Replacing the regexp and replace function with a loop improves
performance by ~60-200%.

PR-URL: #5360
Reviewed-By: James M Snell <[email protected]>
@MylesBorins

MylesBorins commented Jul 11, 2016

Copy link
Copy Markdown
Contributor

I've gone ahead and added this to v4.x-staging and will include it in the v4.5.0 rc.

@evanlucas please let me know if there are any accompanying patch's we need to make this work

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MylesBorins MylesBorins added land-on-v4.x and removed lts-watch-v4.x labels Jul 11, 2016
@MylesBorins MylesBorins mentioned this pull request Jul 11, 2016
Audit commits not found on v4.x-staging #7661
Closed
@MylesBorins

MylesBorins commented Jul 11, 2016

Copy link
Copy Markdown
Contributor

@evanlucas as a heads up you need to provide the commit before your initial commit when doing the ... syntax to specify a range.

735e0df...c490b8b does not include 735e0df

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

MylesBorins pushed a commit that referenced this pull request Jul 11, 2016
@evanlucas Myles Borins
util: improve util.format performance
9532dd8
By manually copying arguments and breaking the try/catch out, we are
able to improve the performance of util.format by 20-100% (depending on
the types).

PR-URL: #5360
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jul 11, 2016
@mscdex Myles Borins
util: improve format() performance further
34dc1cd
Replacing the regexp and replace function with a loop improves
performance by ~60-200%.

PR-URL: #5360
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jul 11, 2016
@evanlucas Myles Borins
benchmark: add util.format benchmark
d2d5784
PR-URL: #5360
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jul 12, 2016
@evanlucas @MylesBorins
benchmark: add util.format benchmark
fc34e9a
PR-URL: #5360
Reviewed-By: James M Snell <[email protected]>
@evanlucas

evanlucas commented Jul 12, 2016

Copy link
Copy Markdown
Contributor Author

@thealphanerd there shouldn't be anything else need to land these. Thanks for the heads up on the range syntax as well :]

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

MylesBorins pushed a commit that referenced this pull request Jul 12, 2016
@evanlucas Myles Borins
util: improve util.format performance
72fb281
By manually copying arguments and breaking the try/catch out, we are
able to improve the performance of util.format by 20-100% (depending on
the types).

PR-URL: #5360
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jul 12, 2016
@mscdex Myles Borins
util: improve format() performance further
d0bf09d
Replacing the regexp and replace function with a loop improves
performance by ~60-200%.

PR-URL: #5360
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jul 12, 2016
@evanlucas Myles Borins
benchmark: add util.format benchmark
b0ab564
PR-URL: #5360
Reviewed-By: James M Snell <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Jul 12, 2016
v4.5.0 proposal #7688
Merged
MylesBorins pushed a commit that referenced this pull request Jul 14, 2016
@evanlucas Myles Borins
benchmark: add util.format benchmark
aa7ca85
PR-URL: #5360
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jul 14, 2016
@evanlucas Myles Borins
benchmark: add util.format benchmark
08cd81b
PR-URL: #5360
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

benchmark Issues and PRs related to Node.js benchmarks and benchmarking infrastructure. performance Issues and PRs related to the performance of Node.js. util Issues and PRs related to the built-in util module.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@evanlucas @mscdex @jasnell @MylesBorins
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.