Uh oh!
There was an error while loading. Please reload this page.
src,tools: use template literals - #5778
Conversation
cjihrig
commented
Mar 18, 2016
LGTM |
There was a problem hiding this comment.
Rebased, added newline per @targos, and force pushed.
targos
commented
Mar 18, 2016
One nit, but LGTM if CI is happy |
jasnell
commented
Mar 18, 2016
LGTM |
williamkapke
commented
Mar 19, 2016
Many of these are only doing the string templating at the beginning or at the end. Maybe this has changed and I missed it- but I thought doing concatenation was faster. I admit- these paths are probably not hit too much, but it seems that ALL thing performance get nits ;) |
benjamingr
commented
Mar 19, 2016
None of the paths are hot and I think template strings except where justified specifically by perf makes sense. LGTM and +1 |
Convert string concatenation to template literals. Enforce with lint rule.
Trott
commented
Mar 19, 2016
@williamkapke wrote:
With the caveat that I may simply be doing the benchmark wrong, my tests are showing that template literals are faster. Here's the code. (You'll have to And here are the results I'm getting with Node.js v5.9.0: Not that it really matters because, as @benjamingr points out, none of this is in a hot path.
That has not been my experience. On the contrary, PRs with micro-optimizations on non-hot-path code and with no benchmark showing effectiveness are usually rejected on the grounds that they cause churn and reduce code readability for no measurable benefit. |
targos
commented
Mar 19, 2016
Template strings should be equally fast. They are desugared to string concatenation by V8's parser |
jbergstroem
commented
Mar 20, 2016
LGTM |
benjamingr
commented
Mar 20, 2016
benjamingr
commented
Mar 20, 2016
Cheers f158a86 |
Convert string concatenation to template literals. Enforce with lint rule. PR-URL: #5778 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
williamkapke
commented
Mar 21, 2016
Trott
commented
Mar 21, 2016
Heh, whoops, looks like I flipped the labels in my test. What I have listed for string concatenation was actually for template literals and vice versa. String concatenation seems to be somewhere between 9% and 18% faster, at least on the machines I have available to test on, and using Node.js 5.9.0. Not enough to worry about for things that only happen once, but probably enough to think twice about extreme hot-path code. |
Prefer the use of template string literals over string concatenation in the dns module, makes dns consistent with other modules basically doing nodejs#5778 for it. PR-URL: nodejs#5809 Reviewed-By: James M Snell <jasnell@gmail.com>
Fishrock123
commented
Mar 22, 2016
This rule will be completely invalid as of #5103 |
benjamingr
commented
Mar 22, 2016
@Fishrock123 mind elaborating? Which rule? |
Trott
commented
Mar 22, 2016
@Fishrock123 I checked out your |
Convert string concatenation to template literals. Enforce with lint rule. PR-URL: #5778 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Conflicts: src/.eslintrc src/node.js
MylesBorins
commented
Mar 30, 2016
I'm not 100% convinced this should be backported. @Trott it isn't landing cleanly, would you be willing to manually backport, do you think it is necessary? |
Trott
commented
Mar 30, 2016
Willing to: Sure. Necessary: Meh, could go either way. Here's the PR if you want it: #5960 (If you're not going to use it, just go ahead and close it.) |
MylesBorins
commented
Mar 30, 2016
thanks @Trott |
Convert string concatenation to template literals. Enforce with lint rule. PR-URL: nodejs#5778 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Convert string concatenation to template literals. Enforce with lint rule. PR-URL: #5778 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Pull Request check-list
make -j8 test(UNIX) orvcbuild test nosign(Windows) pass withthis change (including linting)?
test (or a benchmark) included?
existing APIs, or introduces new ones)?
Affected core subsystem(s)
src, tools
Description of change
Convert string concatenation to template literals. Enforce with lint
rule.
This came out of the conversation around #5762. If this is not objectionable, then the idea would be to enable the
prefer-templaterule on other parts of the codebase, moving it incrementally to using template literals instead of string concatenation.