Skip to content

stream: implement WritableBase without buffering

This separates the Writable class into two classes a WritableBase class which implements all Writable logic except for anything related to buffering, and a Writable class which inherits WritableBase and adds the buffering logic.

This is in order to be able to consistently and in a performant way implement Writable streams that want to implement their own buffering or are simply wrapping existing streams.

WritableBase expects 2 methods passed through options:

  • write: which is basically the writeOrBuffer implementation from today.
  • flush: which is basically end() + wait for completion from today.

Note, that this is for now only for internal core usage not meant for public API.

 streams/writable-manywrites.js len=1024 callback='no' writev='no' sync='no' n=1000000                  -0.94 %       ±6.14% ±8.16% ±10.63%
 streams/writable-manywrites.js len=1024 callback='no' writev='no' sync='yes' n=1000000                  5.76 %       ±5.92% ±7.88% ±10.26%
 streams/writable-manywrites.js len=1024 callback='yes' writev='no' sync='no' n=1000000                  2.47 %       ±7.08% ±9.42% ±12.27%
 streams/writable-manywrites.js len=1024 callback='yes' writev='no' sync='yes' n=1000000                 4.11 %       ±6.17% ±8.21% ±10.69%

This will help with making Writablelike implementations where we want to avoid buffering or sequential writes more streams compliant, e.g. OutgoingMessage.

It will also help with some optimization e.g. avoid buffering both input and output of Transform stream by implementing it in terms of Readable + WritableBase instead of Readable + Writable.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Merge request reports

Loading