Repository navigation
listener: reuse unchanged filter chains by their serialized bytes - #49278
Merged
agrawroh merged 7 commits intoNov 22, 2026
Merged
Conversation
Signed-off-by: Rohit Agrawal <rohit.agrawal@databricks.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The hash index retains only one origin chain per hash, so equal-content updates to omitted colliding chains can unnecessarily rebuild them and drain their existing instances.
1 open issue
What changed in this PR
This PR reduces the cost of Envoy listener updates by matching unchanged filter chains using deterministic serialized bytes, with a message-equality fallback.
Changes:
- Indexes filter chains by serialized bytes and tracks reused instances when determining which chains to drain.
- Applies byte-first comparison to default filter-chain reuse and listener diffing.
- Adds regression tests and an unchanged-chain update benchmark covering 1–4096 chains.
| File | Description |
|---|---|
test/common/listener_manager/filter_chain_manager_impl_test.cc |
Tests reserialized payloads, unequal messages with equal hashes, and reuse across updates. |
test/common/listener_manager/filter_chain_benchmark_test.cc |
Benchmarks updates that preserve every filter chain. |
test/common/listener_manager/BUILD |
Adds dependencies for the new tests. |
source/common/listener_manager/listener_impl.cc |
Uses byte-first comparison when diffing default chains. |
source/common/listener_manager/filter_chain_manager_impl.h |
Defines serialized-byte storage and the fallback hash index. |
source/common/listener_manager/filter_chain_manager_impl.cc |
Implements byte-first reuse, fallback comparison, and instance-based draining detection. |
source/common/listener_manager/BUILD |
Adds the hash-set dependency used for draining detection. |
Review effort: Balanced
| if (origin != nullptr) { | ||
| origin_fc_contexts.reserve(origin->fc_contexts_.size()); | ||
| for (const auto& origin_fc_context : origin->fc_contexts_) { | ||
| origin_fc_contexts.emplace(origin_fc_context.second.message_hash, &origin_fc_context); |
Member
Author
There was a problem hiding this comment.
Every origin chain that shares a hash is now kept and compared, so a chain whose hash another chain shares is still reused.
…-chain-reuse-bytes Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Rohit Agrawal <rohit.agrawal@databricks.com>
… path Drain the default filter chain of an in place update only when the new listener does not hold the same filter chain, which drops the second comparison and the accessor it read. Keep the comparison helper local to the filter chain manager, and test that unchanged bytes alone reuse a filter chain. Add benchmarks of updates that encode every filter chain again or change every filter chain. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Rohit Agrawal <rohit.agrawal@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Rohit Agrawal <rohit.agrawal@databricks.com>
… paths Give the default filter chain of the in place update test a NaN, so that only its identity shows the new listener reuses it. Assert that the reencoded test inputs differ in bytes, and that the update benchmarks rebuild no filter chain they mean to reuse. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Rohit Agrawal <rohit.agrawal@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Rohit Agrawal <rohit.agrawal@databricks.com>
Keep every origin filter chain of a MessageUtil::hash() and compare each, since filter chains that differ can share a hash. Share the struct setup of the reserialized tests, fold the default filter chain helper into addActiveListener, and count the changed benchmark's drains before reading its iterations. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Rohit Agrawal <rohit.agrawal@databricks.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Description
This PR makes LDS updates that keep their filter chains cheaper. The filter chain manager finds an unchanged filter chain of the listener it updates by the deterministic serialization of its message, from
MessageUtil::serializeDeterministically()in #49268, instead of hashing and comparing every filter chain message by reflection. Only a filter chain whose bytes are new is hashed by reflection, so that a later update can still find it by its message.A filter chain whose bytes differ but whose message is equal, such as one whose
Anypayloads were encoded again, is still found byMessageUtil::hash()and a message comparison, and every origin filter chain that shares a hash is compared. The default filter chain is compared by its bytes and then by a message comparison. The drain decisions of an in place update now compare the filter chains the new listener holds rather than their messages, for the default filter chain too. A filter chain holding a NaN, which never compares equal to itself, is now reused when its bytes are unchanged, where before it was rebuilt and drained on every in place update.filter_chain_benchmark_testbuilt with-c optat this branch and at its merge base with this branch's benchmark, and run asfilter_chain_benchmark_test --benchmark_filter='FilterChainManager(Build|Update)'five times each, interleaved, on a shared 48-core host, gives these median milliseconds per call, from the merge base to this branch. Every run fell within 15% of its cell's median. A size counts the listener's destination port filter chains, and each listener holds two more.An update that only encodes the filter chains again matches the listener's hash and stops before the filter chain manager, so the second row stands for such filter chains inside an update that changes something else. The last two rows move by at most 16%, close to that spread. In a perf profile of the size 4096 runs, gmock's teardown of the benchmark's mock filter chains takes about half of the cycles of the changed run and a quarter of the first build's, and that cost grows faster than the number of filter chains. These numbers cover the filter chain manager's part of an update. Decoding and validating the listener and hashing its whole message by reflection come before it, and a local benchmark of that hash over the same listeners took about 5.3 ms at size 4096.
This PR was written with AI assistance.
Commit Message: listener: reuse unchanged filter chains by their serialized bytes
Additional Description:
Risk Level: Low
Testing: Added Tests
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A
This pull request and its description were written by Isaac.