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: https://github.com/nodejs/node/pull/29122
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Anna Henningsen 2019-08-10 23:18:13 +02:00 committed by Michaël Zasso
parent b4cfa521b8
commit b2c7c51d0b
No known key found for this signature in database
GPG Key ID: 770F7A9A5AE15600

View File

@ -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);
{
@ -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_ =