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 — lib: replace sprintf-like format to template string literal by yosuke-furukawa · Pull Request #691 · nodejs/node

Conversation

@yosuke-furukawa

@yosuke-furukawa yosuke-furukawa commented Feb 2, 2015

Copy link
Copy Markdown
Member

Template String Literal is faster than sprintf-like format string.

http://jsperf.com/template-literal-vs-string-plus/2
2015-02-03 1 33 05

And, I think template string literal is easier to understand than sprintf.

Sorry, something went wrong.

Uh oh!

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

All reactions
bnoordhuis
bnoordhuis reviewed Feb 2, 2015
View reviewed changes
Comment thread lib/net.js Outdated

@bnoordhuis bnoordhuis Feb 2, 2015

Copy link
Copy Markdown
Member

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 is a bit at odds with the house style. Maybe like this?

debug(`binding to localAddress: ${localAddress} ` +
      `and localPort: ${localPort}`);

Sorry, something went wrong.

Uh oh!

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

All reactions
@bnoordhuis

bnoordhuis commented Feb 2, 2015

Copy link
Copy Markdown
Member

This looks like an unequivocally good change to me. If you address the nit, I'll land it. Thanks, Yosuke.

All reactions

Sorry, something went wrong.

Uh oh!

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

@tellnes

tellnes commented Feb 2, 2015

Copy link
Copy Markdown
Contributor

Is this rely faster? When iojs is not printing debug output, then debug will be a noop. So that boils it down to which is faster of calling a noop with multiple arguments or a noop with one string composed with template string literal.

All reactions

Sorry, something went wrong.

Uh oh!

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

charmander
charmander reviewed Feb 2, 2015
View reviewed changes
Comment thread lib/timers.js Outdated

@charmander charmander Feb 2, 2015

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.

Don’t add space before :.

Sorry, something went wrong.

Uh oh!

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

All reactions
@Qard

Qard commented Feb 2, 2015

Copy link
Copy Markdown
Member

It seems our linter doesn't understand template strings. It complains that there needs to be spaces before : symbols inside of the strings.

All reactions

Sorry, something went wrong.

Uh oh!

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

@rvagg

rvagg commented Feb 3, 2015

Copy link
Copy Markdown
Member

I wonder if util.format could be improved for the simple cases .. sounds like feature bloat has slowed it down somewhat.

And, fascinating that template strings are faster than concatenation.

One thing to consider here re perf is that all of these changes are are almost irellevant for performance because they are debug or throw situations and almost all involve using console (therefore sync) output anyway, so minor JS gains will likely be made insignificant. As a rule, I'm in favour of keeping things maintainable and grokkable over chasing tiny performance increases but for me the question is still open as to whether template strings used like this pass this bar--perhaps they do and we'll all be used to looking at them in all our code from now on?

/cc @caitp who I suspect may be interested in this change

All reactions

Sorry, something went wrong.

Uh oh!

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

@jbergstroem

jbergstroem commented Feb 3, 2015

Copy link
Copy Markdown
Member

@rvagg I think the template strings are a readability improvement.

All reactions

Sorry, something went wrong.

Uh oh!

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

@caitp

caitp commented Feb 3, 2015

Copy link
Copy Markdown
Contributor

And, fascinating that template strings are faster than concatenation.

I'm certainly interested in this statement, since template literals are desugared to string concatenation during parsing. Tagged templates are likely to be quite a bit slower as well, because of the rather expensive caching mechanism.

That said, go for it

All reactions

Sorry, something went wrong.

Uh oh!

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

@yosuke-furukawa
lib: replace sprintf-like format to template string literal
ad28e03
@yosuke-furukawa

yosuke-furukawa commented Feb 3, 2015

Copy link
Copy Markdown
Member Author

Thank you for comments.

I think template string literals have 2 pros.

  1. faster than util.format.
  2. improve readability compared to string concatenation.

So I suggest this pull request.

@bnoordhuis @charmander
Thanks for review.
When I fixed your review comments, Closure linter reports Missing space before ":" messages. the linter does not recognize ${foo}: var style strings. I reported this issue to closure linter.

Currently, I would like to replace some sprintf-like strings that are not reported by closure linter.
When the issue of closure linter is fixed or we change our linter tool, I would like to replace all sprintf-like strings to template string literals.

All reactions

Sorry, something went wrong.

Uh oh!

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

@sam-github

sam-github commented Feb 3, 2015

Copy link
Copy Markdown
Contributor

I'll take you word for it that string interpolation is faster in general. But the debug statements you changed actually end up as no-ops when NODE_DEBUG is not set to enable the output. Before, that mean no string formatting happened. Now, the interpolation happens even when the string is discarded, unless v8 is smart enough to realize the string is passed to a function that doesn't use it, and so avoids doing interpolation?

All reactions

Sorry, something went wrong.

Uh oh!

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

@caitp

caitp commented Feb 3, 2015

Copy link
Copy Markdown
Contributor

v8 is smart enough to realize the string is passed to a function that doesn't use it, and so avoids doing interpolation?

It's possible that this could happen in crankshaft (likely does not yet happen in turbofan), in hot functions. But full-codegen will not get rid of unused interpolated strings. However, string interpolation can potentially have side effects, so it's possible that those side effects would prevent them from being removed even in crankshaft

All reactions

Sorry, something went wrong.

Uh oh!

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

@vkurchatkin

vkurchatkin commented Feb 23, 2015

Copy link
Copy Markdown
Contributor

Going to close this for now as it mostly changes debug messages. Also linter is not particularly happy with template strings

All reactions

Sorry, something went wrong.

Uh oh!

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

@vkurchatkin vkurchatkin closed this Feb 23, 2015
@yosuke-furukawa yosuke-furukawa mentioned this pull request Apr 29, 2015
tools: switch from closure-linter to eslint #1539
Closed
@jefeaguila jefeaguila mentioned this pull request Feb 11, 2024
[Snyk] Fix for 1 vulnerabilities jefeaguila/node#37
Open
@buzzlightyear726 buzzlightyear726 mentioned this pull request Feb 11, 2024
[Snyk] Fix for 1 vulnerabilities buzzlightyear726/node#39
Open
@jefeaguila jefeaguila mentioned this pull request Feb 11, 2024
[Snyk] Fix for 1 vulnerabilities jefeaguila/node#41
Open
@buzzlightyear726 buzzlightyear726 mentioned this pull request Feb 11, 2024
[Snyk] Fix for 1 vulnerabilities buzzlightyear726/node#44
Open
@Renukaloch Renukaloch mentioned this pull request Feb 11, 2024
[Snyk] Fix for 1 vulnerabilities Renukaloch/node#26
Open
@buzzlightyear726 buzzlightyear726 mentioned this pull request Feb 12, 2024
[Snyk] Fix for 1 vulnerabilities buzzlightyear726/node#51
Open
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

None yet

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.

10 participants

@yosuke-furukawa @bnoordhuis @tellnes @Qard @rvagg @jbergstroem @caitp @sam-github @vkurchatkin @charmander
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.