Skip to content

streams: 5% throughput gain when sending small chunks

Improves the performance when moving small buffers by 5%, and it adds a benchmark to avoid regression in that area. In all other cases it is equally performant current master. Some cases turns out to be faster with this patch, especially in cluster under high load. It also tidy up the clearBuffer method, moving most of the not-necessary code out from the hot code path.

Full performance results available at: https://gist.github.com/mcollina/717c35ad07d15710b6b9.

These are the relevant lines, before:

net/net-c2s-cork.js
net/net-c2s-cork.js len=4 type=buf dur=5: 0.07900
net/net-c2s-cork.js len=8 type=buf dur=5: 0.16693
net/net-c2s-cork.js len=16 type=buf dur=5: 0.32318
net/net-c2s-cork.js len=32 type=buf dur=5: 0.56029
net/net-c2s-cork.js len=64 type=buf dur=5: 1.31117
net/net-c2s-cork.js len=128 type=buf dur=5: 2.19901
net/net-c2s-cork.js len=512 type=buf dur=5: 4.64193
net/net-c2s-cork.js len=1024 type=buf dur=5: 5.46635

and after:

net/net-c2s-cork.js
net/net-c2s-cork.js len=4 type=buf dur=5: 0.08748
net/net-c2s-cork.js len=8 type=buf dur=5: 0.17220
net/net-c2s-cork.js len=16 type=buf dur=5: 0.33850
net/net-c2s-cork.js len=32 type=buf dur=5: 0.61596
net/net-c2s-cork.js len=64 type=buf dur=5: 1.35606
net/net-c2s-cork.js len=128 type=buf dur=5: 2.40356
net/net-c2s-cork.js len=512 type=buf dur=5: 4.86006
net/net-c2s-cork.js len=1024 type=buf dur=5: 5.41967

This were taken on a Macbook Pro 2014 (i7, 16 GB of RAM), and there is quite a variance here. If anybody has a physical linux box (non-virtualized) and wants to test, please do.

This follow up the work on https://github.com/nodejs/node/pull/3751.

cc @chrisdickinson @jasnell @Geek @cjihrig @nodejs/streams

Merge request reports

Loading