-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
buffer: Reverting change in let to fix regressions in buffer operations #5819
Conversation
@@ -292,7 +292,7 @@ Buffer.concat = function(list, length) { | |||
|
|||
var buffer = Buffer.allocUnsafe(length); | |||
var pos = 0; | |||
for (let i = 0; i < list.length; i++) { | |||
for (i = 0; i < list.length; i++) { |
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.
Just wondering why no var here. Looks like it was there previously 2ac47f8. At this point since its a jslint error all I can think of is that we have tightened up the lint rules ?
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.
So this was to address a lint issue.
Really the var i
in the for loop before should be declared outside of the if statement, so have added another commit to fix this,
Can you include specific information about the regression in the commit message? I'm not sure if this is testable, but in the future when a developer wants to reintroduce let it will be helpful to clearly understand why this was reverted. Also include a Code change LGTM. |
LGTM (with @trevnorris' nits addressed) |
Lgtm |
nit: The two commits should be squash, and the commit message should be wrapped to 72 characters (currently the first lint in the comment is 73) otherwise LGTM |
Using let in for loops showed a regression in 4.4.0. @ofrobots suggested that we avoid using let in for loops until TurboFan becomes the default optimiser. The regression that was detected was when looking at how long it took to create a new buffer from an array of data. When using `for (let i=0; i<length; i++) ` we saw the operation take almost 40% longer compared to `var i=0`. Ref: https://github.com/nodejs/benchmarking/issues/38
Have squashed the commits and expanded commit message. |
👍 |
excellent thanks |
Isn't it |
@mscdex perhaps we should open another issue regarding no longer using let in the code base... there are quite a few lets (including others in for loops). The biggest push back I saw what that it is a micro optimization for non-hot code Thoughts? |
I just did a quick test, similar to the benchmark I ran originally, but this time looking at I got two builds, one with var result; and the second with let result; first of all, with let *var_tostring/Release/node to-string-test/to-string-test.js * The amount the results are bouncing around, I'd suggest that the two are performing the same. My benchmark, was measuring how many operations /second I could get when repeating this: var TEXT = "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.";
var ITERATIONS = 200000;
var buffer = new Buffer(TEXT, 'utf-8');
var stringFromBuffer;
function test() {
for(var i=0;i<ITERATIONS;i++) {
stringFromBuffer = buffer.toString();
}
}
harness.run_test(test); |
LGTM, new CI: https://ci.nodejs.org/job/node-test-pull-request/2038 |
ok looks like we have a number of lgtm. @benjamingr you planning to land ? If not I can look at doing it later today |
Sure, I'll land. |
Using let in for loops showed a regression in 4.4.0. @ofrobots suggested that we avoid using let in for loops until TurboFan becomes the default optimiser. The regression that was detected was when looking at how long it took to create a new buffer from an array of data. When using `for (let i=0; i<length; i++) ` we saw the operation take almost 40% longer compared to `var i=0`. PR-URL: #5819 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Myles Borins <[email protected]> Ref: https://github.com/nodejs/benchmarking/issues/38
Landed in 443c2d5 , thanks! |
Using let in for loops showed a regression in 4.4.0. @ofrobots suggested that we avoid using let in for loops until TurboFan becomes the default optimiser. The regression that was detected was when looking at how long it took to create a new buffer from an array of data. When using `for (let i=0; i<length; i++) ` we saw the operation take almost 40% longer compared to `var i=0`. PR-URL: #5819 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Myles Borins <[email protected]> Ref: https://github.com/nodejs/benchmarking/issues/38
@nodejs/lts we usually wait for things to spend time on v5 before backporting. This change is unlikely to cause breakage, and will result in immediate performance improvements. Are people opposed to having this land in this weeks release? |
No objections |
Using let in for loops showed a regression in 4.4.0. @ofrobots suggested that we avoid using let in for loops until TurboFan becomes the default optimiser. The regression that was detected was when looking at how long it took to create a new buffer from an array of data. When using `for (let i=0; i<length; i++) ` we saw the operation take almost 40% longer compared to `var i=0`. PR-URL: #5819 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Myles Borins <[email protected]> Ref: https://github.com/nodejs/benchmarking/issues/38
Using let in for loops showed a regression in 4.4.0. @ofrobots suggested that we avoid using let in for loops until TurboFan becomes the default optimiser. The regression that was detected was when looking at how long it took to create a new buffer from an array of data. When using `for (let i=0; i<length; i++) ` we saw the operation take almost 40% longer compared to `var i=0`. PR-URL: #5819 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Myles Borins <[email protected]> Ref: https://github.com/nodejs/benchmarking/issues/38
Pull Request check-list
Please make sure to review and check all of these items:
make -j8 test
(UNIX) orvcbuild test nosign
(Windows) pass withthis change (including linting)?
test (or a benchmark) included?
existing APIs, or introduces new ones)?
NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.
Affected core subsystem(s)
buffer
Description of change
Using let in for loops showed a regression in 4.4.0. @ofrobots suggested
that we avoid using let in for loops until TurboFan becomes the default
optimiser.
As discussed in nodejs/benchmarking#38