Skip to content

Commit 156f2f3

Browse files
addaleaxBethGriggs
authored andcommittedAug 15, 2019
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: #29124 PR-URL: #29122 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 10f05b6 commit 156f2f3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed
 

‎src/node_http2.cc

+5-4
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ Http2Session::Http2Session(Environment* env,
668668
// fails.
669669
CHECK_EQ(fn(&session_, callbacks, this, *opts, *allocator_info), 0);
670670

671-
outgoing_storage_.reserve(4096);
671+
outgoing_storage_.reserve(1024);
672672
outgoing_buffers_.reserve(32);
673673

674674
{
@@ -1993,9 +1993,10 @@ Http2Stream::Http2Stream(
19931993

19941994
// Limit the number of header pairs
19951995
max_header_pairs_ = session->GetMaxHeaderPairs();
1996-
if (max_header_pairs_ == 0)
1997-
max_header_pairs_ = DEFAULT_MAX_HEADER_LIST_PAIRS;
1998-
current_headers_.reserve(max_header_pairs_);
1996+
if (max_header_pairs_ == 0) {
1997+
max_header_pairs_ = DEFAULT_MAX_HEADER_LIST_PAIRS;
1998+
}
1999+
current_headers_.reserve(std::min(max_header_pairs_, 12u));
19992000

20002001
// Limit the number of header octets
20012002
max_header_length_ =

0 commit comments

Comments
 (0)
Please sign in to comment.