Skip to content

Commit 23b0db5

Browse files
addaleaxtargos
authored andcommitted
http2: shrink default vector::reserve() allocations
Allocating memory upfront comes with overhead, and in particular, `std::vector` implementations do not necessarily return memory to the system when one might expect that (e.g. after shrinking the vector). PR-URL: #29122 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 4f10ac3 commit 23b0db5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/node_http2.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ Http2Session::Http2Session(Environment* env,
639639
// fails.
640640
CHECK_EQ(fn(&session_, callbacks, this, *opts, *allocator_info), 0);
641641

642-
outgoing_storage_.reserve(4096);
642+
outgoing_storage_.reserve(1024);
643643
outgoing_buffers_.reserve(32);
644644

645645
{
@@ -1914,7 +1914,7 @@ Http2Stream::Http2Stream(Http2Session* session,
19141914
if (max_header_pairs_ == 0) {
19151915
max_header_pairs_ = DEFAULT_MAX_HEADER_LIST_PAIRS;
19161916
}
1917-
current_headers_.reserve(max_header_pairs_);
1917+
current_headers_.reserve(std::min(max_header_pairs_, 12u));
19181918

19191919
// Limit the number of header octets
19201920
max_header_length_ =

0 commit comments

Comments
 (0)