joyent/node — pull request #8407 by kennyluck (2014-09-19 16:07:08+00:00)
Title: buffer: improve Buffer constructor

Increase the performance of new Buffer construction by initializing all properties before SetIndexedPropertiesToExternalArrayData call.

The following measurement is by @JacksonTian. Test case:

```
$ cat new_buffer.js
var runBenchmark = function (byteLength) {
console.time('byte length: ' + byteLength);
for (var i = 0; i < 1000000; i++) {
new Buffer(byteLength);
}
console.timeEnd('byte length: ' + byteLength);
};

runBenchmark(1);
runBenchmark(8);
runBenchmark(64);
runBenchmark(512);
runBenchmark(4096);
```

before this patch:

```
byte length: 1: 8333ms
byte length: 8: 7790ms
byte length: 64: 7502ms
byte length: 512: 7774ms
byte length: 4096: 9763ms
```

after this patch:

```
byte length: 1: 411ms
byte length: 8: 376ms
byte length: 64: 347ms
byte length: 512: 832ms
byte length: 4096: 2631ms
```

(I am sending this patch on behalf of Alibaba's JavaScript engine team. Happy BABA IPO :)