stream: keep webstreams nil requests in fast mode - #66230
Conversation
|
Review requested:
|
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>
992b90b to
bc320cd
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66230 +/- ##
==========================================
+ Coverage 90.29% 90.37% +0.08%
==========================================
Files 790 790
Lines 272880 274499 +1619
Branches 52103 52562 +459
==========================================
+ Hits 246385 248078 +1693
+ Misses 16936 16891 -45
+ Partials 9559 9530 -29
🚀 New features to boost your workflow:
|
Controller instances declared only [kType] and set [kState] later in the setup function, so each construction took a shape transition when setup added the slot. Declaring [kState] keeps the slot in the initial map and makes the setup assignment an in-place store. Applied to the readable default, readable byte, writable, and transform controllers so all four share the same instance shape. Assisted-by: pi Signed-off-by: Matteo Collina <hello@matteocollina.com>
Commit Queue failedThis pull request has multiple commits, but no landing policy was selected. Add
commit-queue-squash
The pull request was removed from the Commit Queue and labeled
commit-queue-failed
Full Commit Queue output |
|
Landed in cff7b12 |
Round 19 of the webstreams performance work (follows #66154). A small one: two shared sentinel objects on the writable side were in dictionary mode, and every write and every pipe paid for it.
Nil requests in fast mode
The shared "no pending request" records in
writablestream.js(kNilRequest,kNilPendingAbortRequest) were{ __proto__: null, ... }literals, which V8 creates in dictionary mode (the same trap #65625 removed from the per-stream state records). They sit ininFlightWriteRequest,closeRequestandpendingAbortRequestwhenever nothing is pending, and theirpromisefield is checked several times per write, so each of those loads was a hash lookup. They are now built as plain literals and get their null prototype afterwards withObjectSetPrototypeOf(), which keeps them in fast mode (only an object created with a null prototype starts in dictionary mode).Readable controllers: no throwaway state object
ReadableStreamDefaultControllerandReadableByteStreamControllerinitialized[kState]with an empty object that setup replaced immediately. The field initializer is gone, matching the writable and transform controllers; every construction site goes straight into setup.New benchmark
benchmark/webstreams/writable-write.js: nothing inbenchmark/webstreamsdroveWritableStreamDefaultWriter.write()directly (awaiteach write, or queue them all).Benchmarks
node benchmark/compare.js --runs 20on the final code (pipe-to, pipe-through, lifecycle, writable-write), significant rows only:writable-writeis noisy on this machine: an earlier 30-run pass measuredawaitat +6.5 % () andqueuedat +3.6 % (); herequeuedis +2.6 % ±3.0 %.An earlier full-suite run (creation, tee, readable-read, readable-read-buffered, readable-async-iterator, from, js_transfer as well) showed no other significant change; its one negative flag,
creation.js kind='ReadableStream.tee'at −3.6 % (*), re-ran at 30 runs as −2.05 % ±2.14 %, not significant.No behavior change: a 48-scenario microtask-ordering stress logs identically against
main, and WPT streams plus the webstreams parallel batch are green.AI generated, humanly reviewed.