This commit is contained in:
Ayoub Mrini 2025-08-05 21:30:52 +01:00 committed by GitHub
commit 74b66c68d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 3 deletions

View File

@ -18,11 +18,20 @@ import (
"errors"
"fmt"
"math"
"sync"
"github.com/prometheus/prometheus/model/histogram"
"github.com/prometheus/prometheus/model/value"
)
// floatHistogramChunkAppenderIterPool is exclusively used in Appender() to help reduce
// allocations under heavy usage.
var floatHistogramChunkAppenderIterPool = sync.Pool{
New: func() interface{} {
return &floatHistogramIterator{}
},
}
// FloatHistogramChunk holds encoded sample data for a sparse, high-resolution
// float histogram.
//
@ -104,7 +113,8 @@ func (c *FloatHistogramChunk) Compact() {
// Appender implements the Chunk interface.
func (c *FloatHistogramChunk) Appender() (Appender, error) {
it := c.iterator(nil)
it := c.iterator(floatHistogramChunkAppenderIterPool.Get().(*floatHistogramIterator))
defer floatHistogramChunkAppenderIterPool.Put(it)
// To get an appender, we must know the state it would have if we had
// appended all existing data from scratch. We iterate through the end

View File

@ -18,11 +18,20 @@ import (
"errors"
"fmt"
"math"
"sync"
"github.com/prometheus/prometheus/model/histogram"
"github.com/prometheus/prometheus/model/value"
)
// histogramChunkAppenderIterPool is exclusively used in Appender() to help reduce
// allocations under heavy usage.
var histogramChunkAppenderIterPool = sync.Pool{
New: func() interface{} {
return &histogramIterator{}
},
}
// HistogramChunk holds encoded sample data for a sparse, high-resolution
// histogram.
//
@ -115,7 +124,8 @@ func (c *HistogramChunk) Compact() {
// Appender implements the Chunk interface.
func (c *HistogramChunk) Appender() (Appender, error) {
it := c.iterator(nil)
it := c.iterator(histogramChunkAppenderIterPool.Get().(*histogramIterator))
defer histogramChunkAppenderIterPool.Put(it)
// To get an appender, we must know the state it would have if we had
// appended all existing data from scratch. We iterate through the end

View File

@ -47,6 +47,7 @@ import (
"encoding/binary"
"math"
"math/bits"
"sync"
"github.com/prometheus/prometheus/model/histogram"
)
@ -55,6 +56,13 @@ const (
chunkCompactCapacityThreshold = 32
)
// xorAppenderIterPool is exclusively used in Appender() to help reduce allocations under heavy usage.
var xorAppenderIterPool = sync.Pool{
New: func() interface{} {
return &xorIterator{}
},
}
// XORChunk holds XOR encoded sample data.
type XORChunk struct {
b bstream
@ -98,7 +106,8 @@ func (c *XORChunk) Compact() {
// It is not valid to call Appender() multiple times concurrently or to use multiple
// Appenders on the same chunk.
func (c *XORChunk) Appender() (Appender, error) {
it := c.iterator(nil)
it := c.iterator(xorAppenderIterPool.Get().(*xorIterator))
defer xorAppenderIterPool.Put(it)
// To get an appender we must know the state it would have if we had
// appended all existing data from scratch.