stream: create write request objects lazily · nodejs/node@1560521 · GitHub
Skip to content

Commit 1560521

Browse files
mcollinaaduh95
authored andcommitted
stream: create write request objects lazily
Every stream write created a WriteWrap JS object up front, even though most writes complete synchronously via uv_try_write() and never use it. Let stream_base_commons pass null instead of a request object. StreamBase::Write() already creates the wrap object only when the write does not complete synchronously; return that object to JS (which attaches oncomplete/callback to it) and a plain error code otherwise. Writes that complete synchronously now cross the JS/C++ boundary once and allocate nothing. Callers that pass in a request object (child_process IPC, webstreams adapters) behave as before. Since Http2Stream::DoWrite() can invoke the completion callback synchronously - before JS has attached oncomplete - such completions are now recorded on the request object's writeStatus field and replayed by stream_base_commons after dispatch. This also replaces a Has() plus name-based MakeCallback() pair with a single Get(). Also pre-create the JS fields of WriteWrap instances in the object template, as was already done for ShutdownWrap, so that they are in-object properties. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #64455 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
1 parent 619470a commit 1560521

5 files changed

Lines changed: 185 additions & 87 deletions

File tree

‎lib/internal/stream_base_commons.js‎

Lines changed: 73 additions & 68 deletions

‎src/env_properties.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@
407407
V(writable_string, "writable") \
408408
V(write_host_object_string, "_writeHostObject") \
409409
V(write_queue_size_string, "writeQueueSize") \
410+
V(write_status_string, "writeStatus") \
410411
V(zlib_string, "zlib") \
411412
V(zstd_string, "zstd")
412413

‎src/stream_base.cc‎

Lines changed: 86 additions & 19 deletions

0 commit comments

Comments
 (0)