Skip to content

Conversation

@SOF3
Copy link
Member

@SOF3 SOF3 commented Oct 15, 2025

Description

Intern strings instead of just deep-cloning them to reduce memory usage.

  • unique package uses a WeakMap, so there is no memory leak
  • Only highly repetitive strings are interned. Non-event object names and resource versions rarely repeat, so they are not interned.
  • unique package handles string cloning internally, so we don't need to do it again.

Related issues

Special notes for your reviewer:

@SOF3 SOF3 requested review from Copilot and xuqingyun October 15, 2025 03:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes memory usage in the decaying informer by introducing string interning using Go's unique package. Instead of deep-cloning all strings, it selectively interns highly repetitive strings like cluster, group, resource, and namespace names while continuing to clone less repetitive strings like object names and resource versions.

  • Added InternString helper function using the unique package
  • Updated Key.Clone() and VersionedKey.Clone() methods to intern cluster, group, resource, and namespace fields
  • Updated DecayedOf function to intern namespace and name fields

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pkg/util/reflect/reflect.go Added InternString utility function using unique package
pkg/util/object/key.go Updated Clone methods to intern repetitive string fields instead of cloning
pkg/util/informer/decaying_informer.go Updated DecayedOf to intern namespace and name fields

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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.

1 participant