Repository navigation
perf: eliminate hot-path recompute in the registrar snapshot and xDS cache - #615
Merged
Merged
Conversation
…cache Six pre-verified SAFE fixes from the improvement sweep's hot-path analysis; no behavior change, no ordering change anywhere that feeds xDS output. registrar: - Snapshot keeps an incremental serviceCounts map: the per-event full-scan serviceCountLocked (O(events x total endpoints) under the write lock) becomes a map lookup; ServiceNames iterates the catalog key set (sort kept). 0<->1 transition events are byte-identical. - FullSnapshotEvents(filter): a demand-scoped watcher's initial snapshot skips out-of-scope entries BEFORE allocating their protos (agents reconnect with a fresh filter on every dep-set change, so this was N_reconnects x N_cluster_endpoints allocations during churn). sendFilteredSnapshot keeps its guard as defense in depth. - Broadcast tallies events per type during the fan-out and records one counter Add per type after releasing the read lock, with pre-built per-type measurement options (was one WithAttributes alloc per event per watcher inside the lock). agent xDS cache: - The node-global extension-filter union is computed once per regeneration loop and threaded through, instead of once (or twice) per pod; the shared slice is documented immutable and per-pod prepends still allocate fresh. - The snapshot-shape metric's declared/observed dependency counts ride the existing dep-set memo (same inputs, same validity window incl. the observed-TTL expiry horizon) instead of two full walks per snapshot. - captureVhosts reads the memoized dependency set via a new shared read-only accessor instead of deep-copying it every snapshot. New tests pin the serviceCounts invariant through Apply/Replace and the FullSnapshotEvents filter semantics. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR
The serviceCounts bookkeeping pushed both to 18 (gate is 15). Extract the per-event upsert/remove handling into applyUpsertLocked/ applyRemoveLocked, and allocate the broadcast tally map up front instead of lazily inside the send closure. No behavior change. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR
bpalermo
added a commit
that referenced
this pull request
Aug 1, 2026
Renumber 002 -> 034 (002 is taken by the merged agent-concurrency audit) and revise every code reference after two months of drift: - Ports post-030: inbound is 18008 (defaultInboundPort); the outbound listener is unchanged at 18081 (mesh.ProxyOutboundPort) - Multi-port routing (005): delivery is app_<pod>_<port>, so the original "port is ignored for delivery" semantic is REVERSED — port(s) stay required for demux/EDS; the annotation only changes what the app cluster dials (one socket serves all declared ports) - Redirect-all (022) + mesh DNS narrowed Phase 2's audience; keep it, priority lowered, re-evaluate after Phase 1 - E/W waypoint (019) and cleartext inbound (#421) confirmed covered for free (delivery sits behind the inbound listener) - New facts folded in: UID already fetched but deliberately not persisted (resubscribe.go), storage is protojson in agent/storage, builder is exported GenerateOutboundHTTPListener with the 025/#470 extension union (hoisted per-loop in #615), authz emptyDir socket (#499) documented as the intra-pod precedent (cross-pod still needs the kubelet hostPath), RESULT_IGNORED unmanaged pods, TCP connect-probe analogue on pipes - New constraint: the kubelet-pods mount must not be readOnly (connect(2) on AF_UNIX needs write on the inode; EROFS otherwise) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR
bpalermo
added a commit
that referenced
this pull request
Aug 1, 2026
* docs: proposal 002 — UDS support for pods Plan for letting pods serve on and dial the mesh via Unix domain sockets, in two phases (inbound first). Pathname UDS is mount-namespace-scoped, so the design bridges pod emptyDir volumes to the node proxy through kubelet's pod-volumes directory; abstract sockets and workload hostPath mounts are evaluated and rejected. Registry/EDS endpoints stay TCP :15008, so UDS pods are indistinguishable from TCP pods to clients. Co-Authored-By: Claude Opus 4.8 <[email protected]> * docs(034): re-ground the pod-UDS proposal in the current codebase Renumber 002 -> 034 (002 is taken by the merged agent-concurrency audit) and revise every code reference after two months of drift: - Ports post-030: inbound is 18008 (defaultInboundPort); the outbound listener is unchanged at 18081 (mesh.ProxyOutboundPort) - Multi-port routing (005): delivery is app_<pod>_<port>, so the original "port is ignored for delivery" semantic is REVERSED — port(s) stay required for demux/EDS; the annotation only changes what the app cluster dials (one socket serves all declared ports) - Redirect-all (022) + mesh DNS narrowed Phase 2's audience; keep it, priority lowered, re-evaluate after Phase 1 - E/W waypoint (019) and cleartext inbound (#421) confirmed covered for free (delivery sits behind the inbound listener) - New facts folded in: UID already fetched but deliberately not persisted (resubscribe.go), storage is protojson in agent/storage, builder is exported GenerateOutboundHTTPListener with the 025/#470 extension union (hoisted per-loop in #615), authz emptyDir socket (#499) documented as the intra-pod precedent (cross-pod still needs the kubelet hostPath), RESULT_IGNORED unmanaged pods, TCP connect-probe analogue on pipes - New constraint: the kubelet-pods mount must not be readOnly (connect(2) on AF_UNIX needs write on the inode; EROFS otherwise) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
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.
Summary
Final cohort of the improvement sweep: the six SAFE findings from the hot-path analysis, implemented exactly as specified; the four NEEDS-CARE findings are deferred (listed below). No behavior change; no iteration or sort order that feeds xDS output was touched.
registrar (
internal/server)Snapshot.serviceCounts— the per-event full scan inserviceCountLocked(O(events × total endpoints) under the write lock, per Register/Unregister RPC cluster-wide) becomes an incrementally-maintained map lookup. Invariant: the key set IS the service catalog (no zero rests in the map);ServiceNames()iterates it (sort kept). SERVICE_ADDED/REMOVED transitions are byte-identical.FullSnapshotEvents(filter)— a new watcher's initial snapshot skips out-of-scope entries before allocating their protos. Agents reconnect with a fresh filter on every dependency-set change, so this wasN_reconnects × N_cluster_endpointsproto allocations during a roll — the dominant registrar allocation source under churn.sendFilteredSnapshotkeeps its guard as defense in depth.Addper type after the read lock drops, with measurement options pre-built from the generated enum table (was oneWithAttributesallocation per event per watcher inside the lock). Totals identical.agent xDS cache
AddPod,LoadListenersFromStorage,regenerateAllHTTPListeners,SetCaptureTCPServices,regenerateAllCaptureListeners) instead of once-or-twice per pod. The shared slice is documented immutable; the per-pod authz prepend still allocates fresh. Side benefit:depMuis no longer acquired underlistenerMuon these paths.dependencySetShared()—captureVhosts(read-only membership tests on the hottest path) reads the memo directly instead of deep-copying it per snapshot; the exportedDependencySetstill copies.Deferred (NEEDS-CARE, from the same analysis — candidates for follow-ups)
cap_httproute table keyed on(depGen, captureAuthGen, depSet identity)— the single biggest remaining win, needs per-trigger invalidation testsclusterEntrybesidemtlsCluster(per-snapshot Any-marshals ∝ pods × identities today)AddResource: move marshal+fsync out of the mutex (CNI ADD latency path)RetryPolicyviasync.OnceValue(concurrent-marshalsizeCachecaveat)Tests
New:
TestSnapshot_ServiceCountsStaySynced(pins the invariant through Apply — add / UPDATED-replace / UPDATED-as-add / remove-absent / full-drain / re-add — and Replace) andTestFullSnapshotEvents_Filter(nil = unfiltered, scoped, unknown-service, empty-non-nil). Existing callers updated for the two signature changes.bazel test --test_output=errors //...— 79/79 pass. Note: the repo has no benchmarks; if you want before/after numbers I'd add micro-benchmarks forSnapshot.ApplyandgenerateSnapshotin a follow-up rather than pad this PR.🤖 Generated with Claude Code
https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR