summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-11-29 02:04:46 +0100
committerAnna Henningsen <anna@addaleax.net>2019-12-01 02:14:00 +0100
commit2205f85b2caadee425a0a86bd8cc3bcb889e4bfe (patch)
treec9344a773a788d503aa4f836eb4edbae83356f01 /benchmark
parent596116168a2e2b8dedf31e3d7ca0247fe5c9824b (diff)
downloadandroid-node-v8-2205f85b2caadee425a0a86bd8cc3bcb889e4bfe.tar.gz
android-node-v8-2205f85b2caadee425a0a86bd8cc3bcb889e4bfe.tar.bz2
android-node-v8-2205f85b2caadee425a0a86bd8cc3bcb889e4bfe.zip
stream: improve performance for sync write finishes
Improve performance and reduce memory usage when a writable stream is written to with the same callback (which is the most common case) and when the write operation finishes synchronously (which is also often the case). confidence improvement accuracy (*) (**) (***) streams/writable-manywrites.js sync='no' n=2000000 0.99 % ±3.20% ±4.28% ±5.61% streams/writable-manywrites.js sync='yes' n=2000000 *** 710.69 % ±19.65% ±26.47% ±35.09% Refs: https://github.com/nodejs/node/issues/18013 Refs: https://github.com/nodejs/node/issues/18367 PR-URL: https://github.com/nodejs/node/pull/30710 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/streams/writable-manywrites.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/benchmark/streams/writable-manywrites.js b/benchmark/streams/writable-manywrites.js
index 6fcb07e849..0ed38d0357 100644
--- a/benchmark/streams/writable-manywrites.js
+++ b/benchmark/streams/writable-manywrites.js
@@ -4,14 +4,19 @@ const common = require('../common');
const Writable = require('stream').Writable;
const bench = common.createBenchmark(main, {
- n: [2e6]
+ n: [2e6],
+ sync: ['yes', 'no']
});
-function main({ n }) {
+function main({ n, sync }) {
const b = Buffer.allocUnsafe(1024);
const s = new Writable();
+ sync = sync === 'yes';
s._write = function(chunk, encoding, cb) {
- cb();
+ if (sync)
+ cb();
+ else
+ process.nextTick(cb);
};
bench.start();