benchmark: reduce string concatenations#12455
benchmark: reduce string concatenations#12455vsemozhetbyt wants to merge 4 commits intonodejs:masterfrom vsemozhetbyt:bench-templates
Conversation
benchmark/_http-benchmarkers.js
Outdated
There was a problem hiding this comment.
Why the odd indentation here and elsewhere? Shouldn't they line up with the beginning of the string?
There was a problem hiding this comment.
I've tried to stress the subordinate state of the next part. I'll try to decrease indentation.
benchmark/_benchmark_progress.js
Outdated
There was a problem hiding this comment.
FWIW I'm not particularly a fan of this style to avoid the extra spacing.
There was a problem hiding this comment.
Can you elaborate?
There was a problem hiding this comment.
Using ${ followed by a newline to avoid including spaces due to indentation.
|
Some indentation was reduced. New CI: https://ci.nodejs.org/job/node-test-pull-request/7435/ |
There was a problem hiding this comment.
It's funny we even had a recursive implementation :D
There was a problem hiding this comment.
Yeah, I am even sorry to retire it)
benchmark/buffers/buffer-write.js
Outdated
benchmark/common.js
Outdated
There was a problem hiding this comment.
console.error('bad argument:', arg) ?
There was a problem hiding this comment.
I think this would imply we need inspect() for arg (as we do for Error objects), while arg is a simple string.
benchmark/buffers/buffer-read.js
Outdated
There was a problem hiding this comment.
just a reminder that this will make it impossible to run these benchmarks to compare against anything older than 4.0.0. That's not an objection, by any means.
There was a problem hiding this comment.
Yes, but there were many other template literals in benchmarks before this edition, including common.js.
There was a problem hiding this comment.
At this point I don't think it really matters. I can't see anyone wanting to run the benchmarks for v0.10 or v0.12 anymore, especially since it wouldn't really do any good (it's not as if the V8 team can/will revert to v0.10/v0.12-era V8 code if there is a performance issue in node v4.x+).
There was a problem hiding this comment.
Yep, as I said, it's not an objection. Just noting the change. We may want to let folks know just so that they're aware.
There was a problem hiding this comment.
I think a lot of benchmarks don't run on v4.x or older anyways...I've seen people on IRC
asking why some benchmark doesn't run and turns out they are using v4.x to run it
benchmark/buffers/buffer-swap.js
Outdated
There was a problem hiding this comment.
Definitely not a fan of multiline literals.
|
New CI to be sure: https://ci.nodejs.org/job/node-test-pull-request/7520/ |
|
1 Linux fail seems unrelated. Timeout in UPD. Waiting for #12518 |
|
CI: https://ci.nodejs.org/job/node-test-pull-request/7538/ Sigh... Aborted. New CI: https://ci.nodejs.org/job/node-test-pull-request/7539/ |
PR-URL: #12455 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #12455 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #12455 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #12455 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
|
Landed in bbbb1f6...d8965d5 |
PR-URL: #12455 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #12455 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #12455 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#12735 Refs: nodejs#12455 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Checklist
Affected core subsystem(s)
benchmark
I. Presupposition
String concatenations usually increase syntax noise and add confusion (a reader often has to check if string concatenation or number addition is intended). Moreover, it seems this method is not optimal performance-wise.
II. Cases
This PR aims two cases of string concatenation:
'a' + b + 'c');String('' + notString). This approach, while idiomatic, is not most declarative.III. Performance
The added benchmark compares these variants:
'a' + b + 'c'vs['a', b, 'c'].join('')vs`a${b}c`String(notString)vs'' + notStringvs`${notString}`Results with Node.js 8.0.0 rc:
IV. Commits
Reduce string concatenations: replace concatenations with template literals, rewrap,
String.prototype.repeat(),String(). Some replacements do not add indisputable readability gain, but I tried to be consistent.Add a benchmark for string concatenations vs counterparts.
This commit is added here to avoid PR race condition and merge conflicts. It fixes an URL in
_http-benchmarkers.js(removes duplicate hash symbol).This commit is added here to avoid PR race condition and merge conflicts. It fixes an evident typo in
_http-benchmarkers.js:Error()constructor has only one parameter, whilecallback()has 5 (compare a previous call andcallback()signature).All changed files were minimally tested. CI for linting and new tests concerning benchmarks will be launched.