Skip to content

perf(xds): precompute GAMMA route domains and effective routes at write time (#540) - #551

Merged
bpalermo merged 1 commit into
mainfrom
perf/540-gamma-write-time-precompute
Jul 19, 2026
Merged

bpalermo merged 1 commit into
mainfrom
perf/540-gamma-write-time-precompute

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Fixes #540

Two per-snapshot recomputations of write-time-stable data in agent/internal/xds/cache are now memoized on generation counters, following the #549 depGen idiom (no third caching pattern introduced).

1. Effective (stripped) GAMMA routes — gamma.go

serviceRoutesSnapshot() used to merge local ∪ imported routes, scan every rule for unavailable extension filters, and copy the whole map on every snapshot. It now returns effectiveStrippedRoutesLocked(), a memo keyed on depGen:

  • Invalidation: SetServiceRoutes / SetImportedServiceRoutes already bump depGen; SetAuthzSidecar now bumps too, since authz availability changes the strip result (boot-time in production, but the memo is never served across the flip).
  • The "dropping extAuthz filter" warn now fires once per route mutation instead of once per snapshot.

2. Route-target cap_http domains — capture.go

routeTargetDomains() rebuilt every domain list via fmt.Sprintf in nested loops (base names × ports) per route target on every snapshot. The lists are now precomputed into a routeDomains memo (buildRouteTargetDomains), keyed on two input generations:

  • depGen — covers routes and routeTargetPorts (both writers already bump);
  • a new captureAuthGen — bumped by SetCaptureAuthorities on content change (the SA-backed fqdn source).

captureVhosts reads it through serviceRoutesAndDomainsSnapshot(), which returns routes + domains from the same generation, so the two can never disagree within one snapshot. routeTargetPortsSnapshot (whose only caller was this path) is removed; routeTargetDomains becomes a pure free function called only from the memo rebuild.

Behavior equivalence

  • Byte-identical domains, same order: the per-target algorithm is untouched. The bare-name uniqueness guard previously counted over route targets ∩ dependency set — every effective route target is unconditionally unioned into the dependency set (dependencySetLocked), so counting over all route keys is provably identical (documented on buildRouteTargetDomains).
  • No ordering change: no sorting was added or removed. Vhost emission order is still driven by the same map iterations as before (Go randomizes range order per statement regardless of memoization), and nothing downstream derives ordering from the cached maps — they are lookup-only.
  • Immutability: both memoized maps follow the existing depSet convention — shared with callers, documented read-only, replaced (never mutated) on rebuild. All consumers were audited to be read-only.
  • snapshotMu and the unified-snapshot model are untouched.

Tests

route_memo_test.go:

  • Equivalence vs. reference copies of the old inline computations (strip with authz on/off, filters present/absent, imported+local merge; domains with real ports, port-0/mesh-port skips, bare-name collision vs. unique, SA-backed vs. route-only fqdn derivation).
  • Mutation → recompute for every input class (SetServiceRoutes, SetImportedServiceRoutes, SetAuthzSidecar, SetRouteTargetPorts, SetCaptureAuthorities), plus content-equal authority replacement does not invalidate.
  • No recompute on repeated snapshots without mutation (memo pointer identity, same style as dependencies_memo_test.go).

Existing capture_test.go / chain_seam_test.go vhost-domain assertions pass unchanged, which independently confirms end-to-end equivalence.

bazel test //agent/... green (23/23); //agent/internal/xds/cache:cache_test green with --@rules_go//go/config:race=true; make gazelle + make format applied.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR

…te time (#540)

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

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR
@bpalermo
bpalermo merged commit d406567 into main Jul 19, 2026
14 checks passed
@bpalermo
bpalermo deleted the perf/540-gamma-write-time-precompute branch July 19, 2026 17:45
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.

perf(xds): precompute GAMMA route domains and extension-strip results at write time

1 participant