-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: little improve for Buffer.concat method #1437
Conversation
When buffer list less than 2, no need to calculate the length. The change's benchmark result is here: https://gist.github.com/JacksonTian/2c9e2bdec00018e010e6 It improve 15% ~ 25% speed when list only have one buffer, to other cases no effect.
if (list.length === 0) | ||
return new Buffer(0); | ||
else if (list.length === 1) | ||
return list[0]; |
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.
By the way, should we follow the below assertions:
assert.equal(Buffer.cancat(anyArray, len).length, len);
however
assert.equal(Buffer.cancat([], 1).length, 1); // this line would fail
assert.equal(Buffer.concat([new Buffer(20)]).length, 10); this line would fail as well and importantly i think we need to cut the buffer to 10.
@JacksonTian I know this should not be related to your patch, but it would be great if this is able to be fixed(bug? unsure) :p though cc @trevnorris
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.
Thanks @yorkie for bringing that up. Let's address that issue in another PR and keep this one simple.
LGTM |
LGTM. Thanks. |
When buffer list less than 2, no need to calculate the length. The change's benchmark result is here: https://gist.github.com/JacksonTian/2c9e2bdec00018e010e6 It improve 15% ~ 25% speed when list only have one buffer, to other cases no effect. PR-URL: #1437 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
LGTM. Thanks @JacksonTian, merged in |
When buffer list less than 2, no need to calculate the length. The change's benchmark result is here: https://gist.github.com/JacksonTian/2c9e2bdec00018e010e6 It improve 15% ~ 25% speed when list only have one buffer, to other cases no effect. PR-URL: nodejs#1437 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
When buffer list less than 2, no need to calculate the length.
The change's benchmark result is here:
https://gist.github.com/JacksonTian/2c9e2bdec00018e010e6
It improve 15% ~ 25% speed when list only have one buffer,
to other cases no effect.