Skip to content

Commit 460f896

Browse files
addaleaxBethGriggs
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). Backport-PR-URL: #29123 PR-URL: #29122 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent f4242e2 commit 460f896

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/node_http2.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ Http2Session::Http2Session(Environment* env,
632632
// fails.
633633
CHECK_EQ(fn(&session_, callbacks, this, *opts, *allocator_info), 0);
634634

635-
outgoing_storage_.reserve(4096);
635+
outgoing_storage_.reserve(1024);
636636
outgoing_buffers_.reserve(32);
637637

638638
{
@@ -1947,7 +1947,7 @@ Http2Stream::Http2Stream(Http2Session* session,
19471947
if (max_header_pairs_ == 0) {
19481948
max_header_pairs_ = DEFAULT_MAX_HEADER_LIST_PAIRS;
19491949
}
1950-
current_headers_.reserve(max_header_pairs_);
1950+
current_headers_.reserve(std::min(max_header_pairs_, 12u));
19511951

19521952
// Limit the number of header octets
19531953
max_header_length_ =

0 commit comments

Comments
 (0)