You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Policy CRDs are deep-copied on every reconcile #9781
The k8s provider lists all policy CRDs (BackendTrafficPolicy, ClientTrafficPolicy, etc) from the cache on every reconcile without UnsafeDisableDeepCopy, so controller-runtime deep-copies every policy object each cycle.
I'm bothered by BTP mostly because I have about 16k BTP objects and with mergeGateways: true this becomes a serious hotspot(see attached flamegraph)
But thhey can't just be added to the existing UnsafeDisableDeepCopy set in kubernetes.go
(where all non gateway api already lived), because the provider mutates what it lists(every processor does policy.Status = gwapiv1.PolicyStatus{})
So I propose two steps to fix:
Move the Status clearing/stripping into a cache Transform.
Deep-copy the object in the status updater's mutators, this trades deep copy per changed policy for a deep copy of all policies per reconcile.
The optimization looks feasible, but I suggest using client.UnsafeDisableDeepCopy only on the hot policy List calls instead of globally through Cache.ByObject.
This avoids deep-copying all policy Specs on every reconcile while keeping the status updater’s cache Get unchanged and safe. Before updating, the asynchronous status writer must fetch the latest object to avoid stale resource versions and retry conflicts, that Get must continue returning a detached object.
#9458 already isolates translator status mutations, and #9514 removed the known BTP Spec mutation. Therefore, a cache transform and status-writer changes should not be necessary for the per-List approach. A regression test should verify that reconciliation leaves the cached policy’s nested Spec and Status unchanged.
The optimization looks feasible, but I suggest using client.UnsafeDisableDeepCopy only on the hot policy List calls instead of globally through Cache.ByObject.
This avoids deep-copying all policy Specs on every reconcile while keeping the status updater’s cache Get unchanged and safe. Before updating, the asynchronous status writer must fetch the latest object to avoid stale resource versions and retry conflicts, that Get must continue returning a detached object.
#9458 already isolates translator status mutations, and #9514 removed the known BTP Spec mutation. Therefore, a cache transform and status-writer changes should not be necessary for the per-List approach. A regression test should verify that reconciliation leaves the cached policy’s nested Spec and Status unchanged.
thanks, it make sense - ready to implement this approach.
Activity
stillya commentedon Aug 18, 2026
ready to contribute if you consider it relevant.
rudrakhp commentedon Sep 7, 2026
The optimization looks feasible, but I suggest using
client.UnsafeDisableDeepCopyonly on the hot policyListcalls instead of globally throughCache.ByObject.This avoids deep-copying all policy Specs on every reconcile while keeping the status updater’s cache
Getunchanged and safe. Before updating, the asynchronous status writer must fetch the latest object to avoid stale resource versions and retry conflicts, thatGetmust continue returning a detached object.#9458 already isolates translator status mutations, and #9514 removed the known BTP Spec mutation. Therefore, a cache transform and status-writer changes should not be necessary for the per-List approach. A regression test should verify that reconciliation leaves the cached policy’s nested Spec and Status unchanged.
rudrakhp commentedon Sep 7, 2026
@arkodg @zirain wdyt?
stillya commentedon Sep 10, 2026
thanks, it make sense - ready to implement this approach.
github-actions commentedon Oct 14, 2026
This issue has been automatically marked as stale because it has not had activity in the last 30 days.
stillya commentedon Oct 14, 2026
/remove-lifecycle rotten
perf: skip deep copy when listing policies in the k8s provider (envoy…
[release/v1.10] cherry pick v1.10.0 (#10541)