Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http2: avoid unnecessary buffer resize #34480

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/node_http2.cc
Expand Up @@ -1761,7 +1761,10 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {

statistics_.data_received += nread;

if (UNLIKELY(stream_buf_offset_ > 0)) {
if (LIKELY(stream_buf_offset_ == 0)) {
// Shrink to the actual amount of used data.
buf.Resize(nread);
} else {
// This is a very unlikely case, and should only happen if the ReadStart()
// call in OnStreamAfterWrite() immediately provides data. If that does
// happen, we concatenate the data we received with the already-stored
Expand All @@ -1782,8 +1785,6 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
DecrementCurrentSessionMemory(stream_buf_.len);
}

// Shrink to the actual amount of used data.
buf.Resize(nread);
IncrementCurrentSessionMemory(nread);

// Remember the current buffer, so that OnDataChunkReceived knows the
Expand Down