Repository navigation
perf(xds): memoize the dependency set behind an input generation counter (#539) - #549
Merged
Merged
Conversation
…ter (#539) dependencySetLocked() rebuilt the node dependency set from scratch on every call — per pod event, per GAMMA/L4 update, per refresh, plus the before/after diff calls in the change-signal paths. Memoize it on an input generation counter (depGen): every writer of any depMu-guarded input bumps it via bumpDepGenLocked, and an unchanged generation serves the cached set. Observed (ODCDS) dependencies expire by wall clock at read time without any mutator running, so the memo also records the earliest observed- entry expiry (depSetExpiry) and rebuilds once that instant passes — expiry semantics are byte-identical to the from-scratch build; prune remains a plain mutator that bumps like the rest. DependencySet() now takes the write lock (a hit may store the memo) and hands external callers a copy, so the shared memoized map can never be mutated; the internal before/after diff paths keep distinct sets because the rebuild after a bump allocates a fresh map. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR
bpalermo
added a commit
that referenced
this pull request
Jul 19, 2026
…te time (#540) (#551) Two per-snapshot recomputations of write-time-stable data in the xDS cache are now memoized on generation counters (the #549 depGen idiom): - serviceRoutesSnapshot: the effective (local ∪ imported) GAMMA rules with unavailable extension filters stripped were merged + strip-scanned (and copied) on EVERY snapshot. Now memoized on depGen; SetServiceRoutes / SetImportedServiceRoutes invalidate via their existing bump, and SetAuthzSidecar bumps too since authz availability changes the strip result. - routeTargetDomains: the cap_http host-match domain lists were rebuilt via fmt.Sprintf in nested loops (base names × ports) per route target on every snapshot. Now precomputed into a routeDomains memo keyed on depGen (routes + routeTargetPorts) and a new captureAuthGen (captureAuthorities → the SA-backed fqdn source); captureVhosts reads the memo through serviceRoutesAndDomainsSnapshot, which hands back routes + domains from the same generation. Behavior is byte-identical: the per-target domain algorithm is unchanged (same domains, same order), the bare-name uniqueness guard counts over the same set (every effective route target is unconditionally in the dependency set), and strip semantics are untouched. No ordering semantics changed — map iteration nondeterminism in vhost emission is pre-existing and unaffected (lookups only; no ordering is derived from the cached maps). Cached maps follow the depSet convention: shared, replaced never mutated. Fixes #540 Claude-Session: https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR Co-authored-by: Claude Fable 5 <[email protected]>
This was referenced Jul 19, 2026
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.
Fixes #539
What
dependencySetLocked()rebuilt the node dependency set from scratch on every call — per pod event, per GAMMA/L4 update, per refresh, plus the extra before/after diff calls in the change-signal paths (setPodDependencies,removePodDependencies,SetStaticDependencies,ObserveDependency). This memoizes the build behind an input generation counter (the safer of the two approaches in the issue — no hand-maintained incremental deltas).How
depGen(guarded bydepMu) counts input mutations. Rule kept trivially auditable: every write underdepMubumps viabumpDepGenLocked(), even for fields the rebuild does not read today (routeTargetPorts,serviceInboundFilters) — over-invalidation costs one recompute, a missed bump serves a stale set (the demand-scoping bug class).setPodDependencies,removePodDependencies,ObserveDependency(incl. pure timestamp refresh),PruneObservedDependencies(when entries expired),SetStaticDependencies,SetCaptureTCPServices,SetServiceRoutes,SetImportedServiceRoutes,SetRouteTargetPorts,SetServiceChainFilters,SetImportedServiceChainFilters,SetServiceInboundFilters,SetTCPServiceRoutes,SetTLSServiceRoutes,SetUDPServiceRoutes, plus thedeclareDepstest helper.depSetExpiry, exact boundarynow <= last+ttl) and rebuilds once that instant passes.PruneObservedDependenciesstays the deletion point and bumps like any mutator; when entries expire is unchanged. TheobservedTTLtest hook is part of the memo key too (depSetTTL).dependencySetLockedreturns the shared memoized map (documented read-only; a rebuild always allocates a fresh map, so the internal before/after diff paths still compare distinct sets).DependencySet()now takes the write lock (a call may store the memo) and returns a copy, preserving the old caller-owns-the-map contract.Tests
New
dependencies_memo_test.go:bazel test //agent/...green (23/23);//agent/internal/xds/cache:cache_testalso green with--@rules_go//go/config:race=true.🤖 Generated with Claude Code
https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR