Uh oh!
There was an error while loading. Please reload this page.
buffer: faster case for create buffer from empty string - #4414
buffer: faster case for create buffer from empty string#4414JacksonTian wants to merge 1 commit into
Conversation
mscdex
commented
Dec 24, 2015
I'm confused, so it got slower after this patch? It went from 2767 ops/sec to 605 ops/sec and 2599 ops/sec to 1249 ops/sec? |
JacksonTian
commented
Dec 24, 2015
@mscdex I updated the results. the buffer result is noisy because I used old version(not lastest version) to run it. |
jbergstroem
commented
Dec 26, 2015
There was a problem hiding this comment.
new is unnecessary anymore since it forces a return of a new Uint8Array.
There was a problem hiding this comment.
I prefer use new with constructor.
There was a problem hiding this comment.
I do, too. I think there's even a linter rule in place for it. Are you fine with it @trevnorris?
There was a problem hiding this comment.
@silverwind The code works fine, but we're allocating an unnecessary object. Though I doubt that has an impact on performance either. Part of the point is that Buffer is not an actual constructor anymore. It's now more of a factory method. But again it's nothing serious or is a change that needs to be made.
trevnorris
commented
Dec 28, 2015
One comment but LGTM. |
jasnell
commented
Jan 15, 2016
New CI, the last one appears to have died completely: https://ci.nodejs.org/job/node-test-pull-request/1246/ |
jasnell
commented
Mar 22, 2016
@JacksonTian ... can you rebase this and update the |
JacksonTian
commented
Mar 23, 2016
Hi, @jasnell , the branch rebased. |
514aa5a to
03579baCompareThere was a problem hiding this comment.
The change to lib/buffer.js LGTM but I wonder if it makes a difference on the benchmark numbers when you hoist out the conditional like this:
if(conf.type==='buffer')for(leti=0;i<n*1024;i++)Buffer.from(zeroBuffer);elseif(conf.type==='string')for(leti=0;i<n*1024;i++)Buffer.from(zeroString);Also, I'm not sure if crankshaft will constant-fold the expression n * 1024 away, you might want to check if caching it makes a difference.
There was a problem hiding this comment.
I think it's unrelated. these code is running in difference process when benchmarking it.
There was a problem hiding this comment.
Sorry if I'm being unclear. What I mean is that the overhead of the check and the multiplication may affect the benchmark results. They probably don't but it would be good to check.
There was a problem hiding this comment.
You mean the conf.type === 'buffer' will be run much times?
在 2016年3月23日,下午9:53,Ben Noordhuis <notifications@github.commailto:notifications@github.com> 写道:
In benchmark/buffers/buffer_zero.js #4414 (comment):
function main(conf) {
var n = +conf.n;
bench.start();
for (let i = 0; i < n * 1024; i++) {
- Buffer.from(zero);
- conf.type === 'buffer' ? Buffer.from(zeroBuffer) : Buffer.from(zeroString);
Sorry if I'm being unclear. What I mean is that the overhead of the check and the multiplication may affect the benchmark results. They probably don't but it would be good to check.—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub https://github.com/nodejs/node/pull/4414/files/03579ba47a711923c67215d63385b60cdf473c98#r57161722
When create Buffer from empty string will touch C++ binding also. This patch can improve edge case ~70% faster.
JacksonTian
commented
Mar 23, 2016
Hi, @bnoordhuis I update the benchmark script. following is result: |
jasnell
commented
Mar 23, 2016
LGTM if @bnoordhuis is happy and CI is green |
jasnell
commented
Mar 23, 2016
When create Buffer from empty string will touch C++ binding also. This patch can improve edge case ~70% faster. PR-URL: #4414 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
jasnell
commented
Mar 27, 2016
CI was green. Landed in afd821a |
When create Buffer from empty string will touch C++ binding also. This patch can improve edge case ~70% faster. PR-URL: #4414 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
evanlucas
commented
Mar 31, 2016
Hm, it looks like this is failing on v5.x right now. Apparently, the following no longer throws an error: |
evanlucas
commented
Mar 31, 2016
It looks like master has https://github.com/nodejs/node/blame/master/lib/buffer.js#L211 and v5.x does not. I'm not sure if that was intentional or not, but I'm a little weary of including this in v5.x for now. I'm going to leave it out of v5.10.0 and we can reevaluate |
jasnell
commented
Mar 31, 2016
Given that the change was an additional throw (and therefore semver major),
|
evanlucas
commented
Mar 31, 2016
Sounds good to me. Thanks! |
When create Buffer from empty string will touch
C++ binding also.
This patch can improve edge case ~70% faster.
following is benchmark results.