Skip to content

Commit 5d7b8bf

Browse files
committed
Remove pointer indirection on contents of bigchunk, for performance
This will save memory and a few CPU cycles. We have to be careful to create the Appender after the chunk is appended to our slice, since it has a pointer to the chunk memory. Signed-off-by: Bryan Boreham <[email protected]>
1 parent f3d3ddb commit 5d7b8bf

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

pkg/chunk/encoding/bigchunk.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const samplesPerChunk = 120
1515
var errOutOfBounds = errors.New("out of bounds")
1616

1717
type smallChunk struct {
18-
*chunkenc.XORChunk
18+
chunkenc.XORChunk
1919
start int64
2020
end int64
2121
}
@@ -63,22 +63,20 @@ func (b *bigchunk) addNextChunk(start model.Time) error {
6363
if err != nil {
6464
return err
6565
}
66-
b.chunks[l-1].XORChunk = compacted.(*chunkenc.XORChunk)
66+
b.chunks[l-1].XORChunk = *compacted.(*chunkenc.XORChunk)
6767
}
6868
}
6969

70-
chunk := chunkenc.NewXORChunk()
71-
appender, err := chunk.Appender()
72-
if err != nil {
73-
return err
74-
}
75-
7670
b.chunks = append(b.chunks, smallChunk{
77-
XORChunk: chunk,
71+
XORChunk: *chunkenc.NewXORChunk(),
7872
start: int64(start),
7973
end: int64(start),
8074
})
8175

76+
appender, err := b.chunks[len(b.chunks)-1].Appender()
77+
if err != nil {
78+
return err
79+
}
8280
b.appender = appender
8381
b.remainingSamples = samplesPerChunk
8482
return nil
@@ -136,7 +134,7 @@ func (b *bigchunk) UnmarshalFromBuf(buf []byte) error {
136134
}
137135

138136
b.chunks = append(b.chunks, smallChunk{
139-
XORChunk: chunk.(*chunkenc.XORChunk),
137+
XORChunk: *chunk.(*chunkenc.XORChunk),
140138
start: int64(start),
141139
end: int64(end),
142140
})

0 commit comments

Comments
 (0)