feat: add clone string to handle memory in cm2 - #4395
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the CM performance metrics protobuf parsing to clone strings extracted via easyproto.FieldContext.String(), preventing returned structs from retaining references to the underlying parse buffer and reducing long-lived memory retention when callers keep parsed records.
Changes:
- Added a
clonedString(*easyproto.FieldContext)helper that wrapsfc.String()and returnsstrings.Clone(...). - Replaced all direct
fc.String()usages in parsing logic withclonedString(&fc)so stored strings no longer reference the input buffer.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (1)
cmd/collectors/cmperf/cmmetrics/metrics.go:290
- The comment has a grammatical error and is missing the subject, which makes the safety rationale unclear. It should explicitly say that the parser clones retained strings.
// buf is reused across messages, which is safe because the
// every string it keeps and never stores a slice of buf.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (1)
cmd/collectors/cmperf/cmmetrics/metrics.go:290
- The comment explaining why reusing
bufis safe is grammatically incorrect ("because the / every string...") and reads like it’s missing the subject (the parser). This makes the rationale harder to understand for future maintainers.
// buf is reused across messages, which is safe because the
// every string it keeps and never stores a slice of buf.
No description provided.