Skip to content

Commit ab97358

Browse files
wdauchycursoragent
andcommitted
upstream: use hash instead of MessageDifferencer for metadata/locality comparison
Replace Protobuf::util::MessageDifferencer with MessageUtil::hash for equality checks in hot paths to reduce CPU during large EDS updates: - updateDynamicHostList: metadata comparison (upstream_impl.cc) - LocalityEndpointEqualTo: locality/endpoint comparison (locality_endpoint.h) Hash comparison is typically faster than reflection-based MessageDifferencer and matches Envoy's MessageLiteDifferencer approach when full protos are disabled. Helps with clusters of ~5k endpoints where these comparisons run per host on each EDS update. Signed-off-by: William Dauchy <william.dauchy@datadoghq.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 268671e commit ab97358

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

source/common/upstream/locality_endpoint.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ struct LocalityEndpointHash {
2020

2121
struct LocalityEndpointEqualTo {
2222
bool operator()(const LocalityEndpointTuple& lhs, const LocalityEndpointTuple& rhs) const {
23-
return Protobuf::util::MessageDifferencer::Equals(std::get<0>(lhs), std::get<0>(rhs)) &&
24-
Protobuf::util::MessageDifferencer::Equals(std::get<1>(lhs), std::get<1>(rhs));
23+
return MessageUtil::hash(std::get<0>(lhs)) == MessageUtil::hash(std::get<0>(rhs)) &&
24+
MessageUtil::hash(std::get<1>(lhs)) == MessageUtil::hash(std::get<1>(rhs));
2525
}
2626
};
2727

source/common/upstream/upstream_impl.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,11 +2343,11 @@ bool BaseDynamicClusterImpl::updateDynamicHostList(
23432343

23442344
hosts_changed |= updateEdsHealthFlag(*host, *existing_host->second);
23452345

2346-
// Did metadata change?
2346+
// Did metadata change? Use hash for faster comparison.
23472347
bool metadata_changed = true;
23482348
if (host->metadata() && existing_host->second->metadata()) {
2349-
metadata_changed = !Protobuf::util::MessageDifferencer::Equivalent(
2350-
*host->metadata(), *existing_host->second->metadata());
2349+
metadata_changed = MessageUtil::hash(*host->metadata()) !=
2350+
MessageUtil::hash(*existing_host->second->metadata());
23512351
} else if (!host->metadata() && !existing_host->second->metadata()) {
23522352
metadata_changed = false;
23532353
}

0 commit comments

Comments
 (0)