Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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).
  • Loading branch information
addaleax committed Aug 14, 2019
commit cda3bad32c78fad45ad671e837c0fdd0031c5d96
9 changes: 5 additions & 4 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,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 @@ -1993,9 +1993,10 @@ Http2Stream::Http2Stream(

// Limit the number of header pairs
max_header_pairs_ = session->GetMaxHeaderPairs();
if (max_header_pairs_ == 0)
max_header_pairs_ = DEFAULT_MAX_HEADER_LIST_PAIRS;
current_headers_.reserve(max_header_pairs_);
if (max_header_pairs_ == 0) {
max_header_pairs_ = DEFAULT_MAX_HEADER_LIST_PAIRS;
}
current_headers_.reserve(std::min(max_header_pairs_, 12u));

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