-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
When XDS config is converted from protobuf into C++ data structures, those data structures are not always as memory efficient as the protobufs, leading to large memory consumption.
Optional sub-messages are often stored as full blown objects, even when the config for them isn't present.
An example of that is RetryPolicy in RDS:
- Route holds an instance of RetryPolicyImpl class:
envoy/source/common/router/config_impl.h
Line 1012 in aa69443
const RetryPolicyImpl retry_policy_; - VitrualHost holds an optional instance of the RetryPolicy protobuf:
envoy/source/common/router/config_impl.h
Line 316 in aa69443
absl::optional<envoy::config::route::v3::RetryPolicy> retry_policy_;
Each of them are 200+ bytes.
Another example are HeaderParsers. There are 2 (request/response) in each Route and each VirtualHost. Even if no headers are present in the config, RDS ends up creating HeaderParser instances:
envoy/source/common/router/header_parser.cc
Line 254 in aa69443
| HeaderParserPtr header_parser(new HeaderParser()); |
A better approach would be to keep a unique_ptr member and only initialize it when config is present. If not, a reference to a default ConstSingleton object can be used.