perf: intern AttachedPolicyRef ID strings#14217
Merged
puertomontt merged 1 commit intoJun 10, 2026
Merged
Conversation
A memory profile of a large production environment showed ~6.6% of the controller's live heap in AttachedPolicyRef.ID: the concatenated ID string is retained in MergeOrigins sets for every route a policy attaches to, so a policy attached to many routes retains many identical copies. Intern the ID via the unique package so all copies share one canonical backing string, and hoist the ID computation out of the per-field loop in MergeOrigins.GetRefCount, which recomputed it once per merged field. Signed-off-by: omar <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces controller heap usage by deduplicating AttachedPolicyRef.ID() strings that are retained across many MergeOrigins sets, and removes redundant per-field recomputation of that ID during merge-origin reference counting.
Changes:
- Intern
AttachedPolicyRef.ID()using Go’suniquepackage so retained copies share a single canonical backing string. - Hoist
policyRef.ID()out of theMergeOrigins.GetRefCountper-field loop to avoid repeated concatenation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/pluginsdk/ir/merge.go | Avoids recomputing the policy ref ID for each merged field when counting references. |
| pkg/pluginsdk/ir/gw.go | Interns the computed policy ref ID string to reduce retained duplicate string backing storage. |
sheidkamp
approved these changes
Jun 10, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Jun 10, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to no response for status checks
Jun 10, 2026
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.
Description
A memory profile of a large production environment showed ~6.6% of the controller's live heap attributed to
AttachedPolicyRef.ID. The concatenated ID string is retained inMergeOriginssets for every route a policy attaches to, so a policy attached to many routes retains many identical copies of the same string.This PR:
uniquepackage, so all retained copies share a single canonical backing string. The interning map is weakly held, so entries are garbage collected once the policy refs go away.policyRef.ID()computation out of the per-field loop inMergeOrigins.GetRefCount, which recomputed the concatenation once per merged field.The emitted Envoy configuration and status reporting are unchanged; only the memory sharing changes.
Change Type
/kind cleanup
Changelog
Additional Notes
An alternative considered was caching the computed ID on the
AttachedPolicyRefstruct, but a lazily-written field would be a data race under concurrent gateway translations; interning achieves the same retained-memory deduplication without changing struct semantics.