mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
stream: amortize writable buffer compaction
Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day> Assisted-by: Codex PR-URL: https://github.com/nodejs/node/pull/65847 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
e3ad68289a
commit
cfee7fa3d9
2 files changed
+26
-1
No files matched your search
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const { Writable } = require('stream');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
count: [1024, 16384, 65536],
|
||||
n: [100],
|
||||
});
|
||||
|
||||
function main({ count, n }) {
|
||||
const chunk = {};
|
||||
let callback;
|
||||
const stream = new Writable({
|
||||
objectMode: true,
|
||||
write(chunk, encoding, cb) { callback = cb; },
|
||||
});
|
||||
|
||||
bench.start();
|
||||
for (let i = 0; i < n; i++) {
|
||||
for (let j = 0; j < count; j++) stream.write(chunk);
|
||||
for (let j = 0; j < count; j++) callback();
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
||||
@@ -787,7 +787,7 @@ function clearBuffer(stream, state) {
|
||||
|
||||
if (i === buffered.length) {
|
||||
resetBuffer(state);
|
||||
} else if (i > 256) {
|
||||
} else if (i > 256 && i * 2 >= buffered.length) {
|
||||
buffered.splice(0, i);
|
||||
state.bufferedIndex = 0;
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user