network: More efficient caching for Envoy socket addresses #37832
+269
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
An LRU cache was introduced to cache
Envoy::Network::Address
instances because they are expensive to create. These addresses are cached for reading source and destination addresses fromrecvmsg
andrecvmmsg
calls on QUIC UDP sockets. The current size of the cache is 4 entries for each IoHandle (i.e. each socket).A locally run CPU profile of Envoy Mobile showed about 1.75% of CPU cycles going towards querying and inserting into the
quic::QuicLRUCache
.Given the small number of elements in the cache, this commit uses a
std::vector
data structure instead ofQuicLRUCache
.QuicLRUCache
,std::vector
, andstd::deque
were compared using newly added benchmark tests, and the following were the results:QuicLRUCache:
std::deque:
std::vector:
std::vector
uses 3.5x less CPU cycles thanquic::QuicLRUCache
and performs very slightly better thanstd::deque
at small cache sizes. If considering creating a bigger cache size (e.g. >= 50 entries),std::deque
may perform better and it's worth profiling, though in such a situation, no cache at all seems to perform better than a cache.Risk Level: low
Testing: unit and benchmark tests
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a