Conversation
Collaborator
|
Review requested:
|
Member
Author
|
cc @nodejs/diagnostics |
Instead of counting buffered outgoing data in bytes (see nodejs#66039, where the cost of Buffer.byteLength on the hot path was raised), expose the outgoing body chunk and its encoding on new diagnostics channels: - http.client.request.bodyChunkSent - http.server.response.bodyChunkSent Subscribed tools can compute the byte length themselves from `data` and `encoding` (`Buffer.byteLength(data, encoding)`), so Node does not pay to measure bytes unless someone is actually reading them. The channel is resolved once in the message constructor (`hasSubscribers` is checked there) and cached on the instance, so the per-chunk write path only reads a cached reference instead of querying the channel on every chunk. Refs: nodejs#66039 Refs: nodejs#57985 Refs: nodejs#46601 Refs: nodejs#46605 Signed-off-by: Matteo Collina <hello@matteocollina.com> Assisted-by: pi
mcollina
force-pushed
the
http-outgoing-body-chunk-diagnostics
branch
from
September 17, 2026 10:12
ad13df4 to
0631fdd
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66081 +/- ##
==========================================
+ Coverage 90.13% 90.26% +0.13%
==========================================
Files 751 789 +38
Lines 253639 271661 +18022
Branches 47790 51852 +4062
==========================================
+ Hits 228618 245224 +16606
- Misses 16264 16905 +641
- Partials 8757 9532 +775
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds two diagnostics channels, http.client.request.bodyChunkSent and http.server.response.bodyChunkSent, that expose the outgoing body chunk and
its encoding. Subscribed tools can compute the byte length of what is being
sent themselves from
dataandencoding(Buffer.byteLength(data, encoding),or data.byteLength for buffers).
This avoids counting buffered outgoing data in bytes on the hot path: Node does not pay to measure the chunk unless someone is actually reading it. The channel (and its subscriber presence) is resolved once in the message
constructor and cached on the instance, so the per-chunk write path only reads
a cached reference.
Alternative to #66039
Refs: #66039
Refs: #57985
Refs: #46601
Refs: #46605