stream: keep webstreams nil requests in fast mode · nodejs/node@e241cb8 · GitHub
Skip to content

Commit e241cb8

Browse files
mcollinaaduh95
authored andcommitted
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: #66230 Reviewed-By: Mattias Buelens <mattias@buelens.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent b7f6a66 commit e241cb8

4 files changed

Lines changed: 42 additions & 9 deletions

File tree

Lines changed: 31 additions & 0 deletions

‎lib/internal/webstreams/readablestream.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ ObjectDefineProperties(ReadableStreamBYOBReader.prototype, {
11401140

11411141
class ReadableStreamDefaultController {
11421142
[kType] = 'ReadableStreamDefaultController';
1143-
[kState] = {};
1143+
[kState];
11441144

11451145
constructor(skipThrowSymbol = undefined) {
11461146
if (skipThrowSymbol !== kSkipThrow) {
@@ -1203,7 +1203,7 @@ ObjectDefineProperties(ReadableStreamDefaultController.prototype, {
12031203

12041204
class ReadableByteStreamController {
12051205
[kType] = 'ReadableByteStreamController';
1206-
[kState] = {};
1206+
[kState];
12071207

12081208
constructor(skipThrowSymbol = undefined) {
12091209
if (skipThrowSymbol !== kSkipThrow) {

‎lib/internal/webstreams/transformstream.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ TransferredTransformStream.prototype[kDeserialize] = () => {};
303303

304304
class TransformStreamDefaultController {
305305
[kType] = 'TransformStreamDefaultController';
306+
[kState];
306307

307308
constructor(skipThrowSymbol = undefined) {
308309
if (skipThrowSymbol !== kSkipThrow) {

‎lib/internal/webstreams/writablestream.js‎

Lines changed: 8 additions & 7 deletions

0 commit comments

Comments
 (0)