Skip to content

Commit

Permalink
http2: shrink default vector::reserve() allocations
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
addaleax authored and targos committed Aug 15, 2019
1 parent 4f10ac3 commit 23b0db5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ Http2Session::Http2Session(Environment* env,
// fails.
CHECK_EQ(fn(&session_, callbacks, this, *opts, *allocator_info), 0);

outgoing_storage_.reserve(4096);
outgoing_storage_.reserve(1024);
outgoing_buffers_.reserve(32);

{
Expand Down Expand Up @@ -1914,7 +1914,7 @@ Http2Stream::Http2Stream(Http2Session* session,
if (max_header_pairs_ == 0) {
max_header_pairs_ = DEFAULT_MAX_HEADER_LIST_PAIRS;
}
current_headers_.reserve(max_header_pairs_);
current_headers_.reserve(std::min(max_header_pairs_, 12u));

// Limit the number of header octets
max_header_length_ =
Expand Down

0 comments on commit 23b0db5

Please sign in to comment.