Skip to content

upstream: Uses a more efficient type for ClusterMap#44006

Merged
RyanTheOptimist merged 7 commits intoenvoyproxy:mainfrom
birenroy:btree-not-map
Mar 23, 2026
Merged

upstream: Uses a more efficient type for ClusterMap#44006
RyanTheOptimist merged 7 commits intoenvoyproxy:mainfrom
birenroy:btree-not-map

Conversation

@birenroy
Copy link
Copy Markdown
Contributor

@birenroy birenroy commented Mar 18, 2026

This change replaces std::map with absl::btree_map, which is more efficient in terms of memory allocations and CPU/memory operations per lookup.

Commit Message: upstream: Uses a more efficient type for ClusterMap
Additional Description:
Risk Level:
Testing: ran unit and integration tests locally
Docs Changes:
Release Notes:
Platform Specific Features:

…-efficient.

Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Biren Roy <birenroy@google.com>
@birenroy
Copy link
Copy Markdown
Contributor Author

/assign @adisuissa

@birenroy
Copy link
Copy Markdown
Contributor Author

/assign @paul-r-gall

Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Biren Roy <birenroy@google.com>
@birenroy
Copy link
Copy Markdown
Contributor Author

I'm having a hard time understanding why //test/extensions/config_subscription/grpc:xds_failover_integration_test is failing. If you have any ideas, they would be much appreciated.

Copy link
Copy Markdown
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I actually have a different PR (#44015) in draft mode at the moment (to make sure it works with all the tests), that takes a different approach by removing the need to use clusters() in many places.
What do you think are the performance tradeoffs between the two approaches (keeping the ordered map vs. avoiding the clusters() invocation)?

@paul-r-gall
Copy link
Copy Markdown
Contributor

@adisuissa I think your PR resolves an orthogonal problem.

@adisuissa
Copy link
Copy Markdown
Contributor

@adisuissa I think your PR resolves an orthogonal problem.

If the ordering is still needed, then the other PR needs to support temporary sorting prior to iterating, which makes the improvement (avoiding the creation of temporary maps/lists) moot.

Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Biren Roy <birenroy@google.com>
@birenroy
Copy link
Copy Markdown
Contributor Author

Alright, I've moved back to using absl::btree_map, which maintains the ordering property. Please take another look.

@birenroy
Copy link
Copy Markdown
Contributor Author

/retest

@pianiststickman
Copy link
Copy Markdown
Contributor

@adisuissa I think your PR resolves an orthogonal problem.

If the ordering is still needed, then the other PR needs to support temporary sorting prior to iterating, which makes the improvement (avoiding the creation of temporary maps/lists) moot.

I don't quite understand this comment - any caller of clusters() can't be relying on its order, because the structure returned by clusters() uses the unordered absl::flat_hash_map already.

@birenroy
Copy link
Copy Markdown
Contributor Author

/assign @RyanTheOptimist

@RyanTheOptimist RyanTheOptimist merged commit 69b5b8e into envoyproxy:main Mar 23, 2026
29 checks passed
@adisuissa
Copy link
Copy Markdown
Contributor

@adisuissa I think your PR resolves an orthogonal problem.

If the ordering is still needed, then the other PR needs to support temporary sorting prior to iterating, which makes the improvement (avoiding the creation of temporary maps/lists) moot.

I don't quite understand this comment - any caller of clusters() can't be relying on its order, because the structure returned by clusters() uses the unordered absl::flat_hash_map already.

That's an important observation. I think what threw me off is the comment, that was added a while ago (implying that this change was intentional):
a2a5fc1#diff-e87368e6d93ba40ac4d6769c47823b899722ace412def9f508c4fc8ceebd2773R329-R330

I wonder if that is no longer the case, and if there are no other dependencies on the order in all other usages. If that's so, absl::flat_hash_map can definitely be used here.

fishcakez pushed a commit to fishcakez/envoy that referenced this pull request Mar 25, 2026
This change replaces `std::map` with `absl::btree_map`, which is more
efficient in terms of memory allocations and CPU/memory operations per
lookup.

Commit Message: upstream: Uses a more efficient type for ClusterMap
Additional Description:
Risk Level:
Testing: ran unit and integration tests locally
Docs Changes:
Release Notes:
Platform Specific Features:

---------

Signed-off-by: Biren Roy <birenroy@google.com>
TAOXUY pushed a commit to TAOXUY/envoy that referenced this pull request Apr 1, 2026
This change replaces `std::map` with `absl::btree_map`, which is more
efficient in terms of memory allocations and CPU/memory operations per
lookup.

Commit Message: upstream: Uses a more efficient type for ClusterMap
Additional Description:
Risk Level:
Testing: ran unit and integration tests locally
Docs Changes:
Release Notes:
Platform Specific Features:

---------

Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Xuyang Tao <taoxuy@google.com>
citrus7 pushed a commit to citrus7/envoy that referenced this pull request Apr 1, 2026
This change replaces `std::map` with `absl::btree_map`, which is more
efficient in terms of memory allocations and CPU/memory operations per
lookup.

Commit Message: upstream: Uses a more efficient type for ClusterMap
Additional Description:
Risk Level:
Testing: ran unit and integration tests locally
Docs Changes:
Release Notes:
Platform Specific Features:

---------

Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Jonathan Wu <jtwu@google.com>
nshipilov pushed a commit to nshipilov/envoy that referenced this pull request Apr 13, 2026
This change replaces `std::map` with `absl::btree_map`, which is more
efficient in terms of memory allocations and CPU/memory operations per
lookup.

Commit Message: upstream: Uses a more efficient type for ClusterMap
Additional Description:
Risk Level:
Testing: ran unit and integration tests locally
Docs Changes:
Release Notes:
Platform Specific Features:

---------

Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Nick Shipilov <nick.shipilov.n@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants