Skip to content

Policy CRDs are deep-copied on every reconcile #9781

Closed

Description

@stillya

Description:

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:

  1. Move the Status clearing/stripping into a cache Transform.
  2. 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.
Image

Activity

  1. stillya commented on Aug 18, 2026

    @stillya
    ContributorAuthor

    ready to contribute if you consider it relevant.

  2. added
    area/translator
    and removed on Sep 7, 2026
  3. rudrakhp commented on Sep 7, 2026

    @rudrakhp
    Member

    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.

  4. rudrakhp commented on Sep 7, 2026

    @rudrakhp
    Member
  5. stillya commented on Sep 10, 2026

    @stillya
    ContributorAuthor

    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.

  6. added this to the v1.10.0-rc.1 Release milestone on Sep 14, 2026
  7. github-actions commented on Oct 14, 2026

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has not had activity in the last 30 days.

  8. stillya commented on Oct 14, 2026

    @stillya
    ContributorAuthor

    /remove-lifecycle rotten

  9. added 2 commits that reference this issue on Nov 4, 2026
    b154c38
    02e9f89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/performancearea/translatorno stalebot

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions