Skip to content

Commit

Permalink
grpc-xDS: reserve vector size
Browse files Browse the repository at this point in the history
Signed-off-by: Adi Suissa-Peleg <[email protected]>
  • Loading branch information
adisuissa committed Sep 19, 2024
1 parent 52d8f34 commit 6b026f6
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions source/extensions/config_subscription/grpc/watch_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ void WatchMap::onConfigUpdate(const Protobuf::RepeatedPtrField<ProtobufWkt::Any>
}

std::vector<DecodedResourcePtr> decoded_resources;
decoded_resources.reserve(resources.size());
for (const auto& r : resources) {
decoded_resources.emplace_back(
DecodedResourceImpl::fromResource((*watches_.begin())->resource_decoder_, r, version_info));
Expand All @@ -227,6 +228,10 @@ void WatchMap::onConfigUpdate(
// into the individual onConfigUpdate()s.
std::vector<DecodedResourcePtr> decoded_resources;
absl::flat_hash_map<Watch*, std::vector<DecodedResourceRef>> per_watch_added;
// If the server behaves according to the protocol, it will only send the
// resources the watch map is interested in. Reserve the correct amount of
// space for the vector for the good case.
decoded_resources.reserve(added_resources.size());
for (const auto& r : added_resources) {
const absl::flat_hash_set<Watch*>& interested_in_r = watchesInterestedIn(r.name());
// If there are no watches, then we don't need to decode. If there are watches, they should all
Expand Down

0 comments on commit 6b026f6

Please sign in to comment.