Skip to content

Commit a2ec191

Browse files
committed
Explicitly reallocate slice to avoid up to 2x overhead
Signed-off-by: Bryan Boreham <[email protected]>
1 parent 53f2043 commit a2ec191

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pkg/chunk/encoding/bigchunk.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ func (b *bigchunk) addNextChunk(start model.Time) error {
6565
}
6666
}
6767

68+
// Explicitly reallocate slice to avoid up to 2x overhead if we let append() do it
69+
if len(b.chunks)+1 > cap(b.chunks) {
70+
newChunks := make([]smallChunk, len(b.chunks), len(b.chunks)+1)
71+
copy(newChunks, b.chunks)
72+
b.chunks = newChunks
73+
}
6874
b.chunks = append(b.chunks, smallChunk{
6975
XORChunk: *chunkenc.NewXORChunk(),
7076
start: int64(start),

0 commit comments

Comments
 (0)