Skip to content

Commit d601f0a

Browse files
authored
Merge pull request #1702 from cortexproject/bigchunk-smaller-slice
Explicitly reallocate bigchunk slice to avoid up to 2x overhead
2 parents 7d13c2f + a2ec191 commit d601f0a

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)