Files
Matteo Collina cff7b12df1 stream: keep webstreams nil requests in fast mode
The shared "no pending request" records in the writable stream were
`__proto__: null` literals, which V8 creates in dictionary mode. They
sit in inFlightWriteRequest, closeRequest and pendingAbortRequest
whenever nothing is pending, and their promise field is checked several
times per write, so those loads did a hash lookup on every write and
every pipe. They are now built as plain literals and get their null
prototype afterwards, which keeps them in fast mode.

The readable controllers also initialized their state slot with an
empty object that setup replaced immediately. That throwaway allocation
is gone, matching the writable and transform controllers.

Add a writable-write benchmark: nothing in benchmark/webstreams drove
WritableStreamDefaultWriter.write() directly.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/66230
Reviewed-By: Mattias Buelens <mattias@buelens.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2026-09-28 07:51:16 +00:00

32 lines
728 B
JavaScript

'use strict';
const common = require('../common.js');
const assert = require('node:assert');
const { WritableStream } = require('node:stream/web');
const bench = common.createBenchmark(main, {
n: [1e5],
type: ['await', 'queued'],
});
async function main({ n, type }) {
let count = 0;
const ws = new WritableStream({
write() {
count++;
},
}, { highWaterMark: type === 'queued' ? n : 1 });
const writer = ws.getWriter();
bench.start();
if (type === 'await') {
for (let i = 0; i < n; i++)
await writer.write('a');
} else {
for (let i = 1; i < n; i++)
writer.write('a');
await writer.write('a');
}
bench.end(n);
await writer.close();
assert.strictEqual(count, n);
}