Skip to content

preserving the capacity of the Symbols slice during resets#7404

Open
SungJin1212 wants to merge 2 commits intocortexproject:masterfrom
SungJin1212:preserve-capacity-symbols-in-resets
Open

preserving the capacity of the Symbols slice during resets#7404
SungJin1212 wants to merge 2 commits intocortexproject:masterfrom
SungJin1212:preserve-capacity-symbols-in-resets

Conversation

@SungJin1212
Copy link
Copy Markdown
Member

This PR optimizes memory allocations in the PRW2 path.

  • Added a Reset() method to the PreallocWriteRequestV2 object that clears the fields while preserving the underlying memory capacity of the Symbols slice.
  • Updated the push handler to reduce memory allocations by reusing request objects from a pool PreallocWriteRequestV2FromPool().

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@SungJin1212 SungJin1212 marked this pull request as draft April 9, 2026 01:36
Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Comment thread pkg/util/push/push.go
// v1 request is put back into the pool by the Distributor.
defer func() {
cortexpb.ReuseWriteRequestV2(&req)
req.Free()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Delete the req.Free() since this path is a http.

Comment thread pkg/util/push/push.go
}

var req cortexpb.PreallocWriteRequestV2
req := cortexpb.PreallocWriteRequestV2FromPool()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Use a req from the pool to reuse the capacity of the Symbols.

Comment on lines +133 to +140
// Reset implements proto.Message and preserves the capacity of the Symbols slice.
func (p *PreallocWriteRequestV2) Reset() {
savedSymbols := p.Symbols
p.WriteRequestV2.Reset()
p.Symbols = savedSymbols[:0]
p.data = nil
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Override a Reset() to preserve the capacity of the Symbols.

@SungJin1212 SungJin1212 force-pushed the preserve-capacity-symbols-in-resets branch from c4cc846 to 402e968 Compare April 17, 2026 07:11
@SungJin1212 SungJin1212 marked this pull request as ready for review April 17, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant