From 65a443e6e370c9996506fb3152db678966e7154d Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 13 Nov 2023 16:20:04 +0000 Subject: [PATCH] TSDB: initialize conflicts map only when we need it. Suggested by @songjiayang. Signed-off-by: Bryan Boreham --- tsdb/head.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tsdb/head.go b/tsdb/head.go index 410a226d8..fb90c9fa0 100644 --- a/tsdb/head.go +++ b/tsdb/head.go @@ -1707,6 +1707,9 @@ func (m seriesHashmap) set(hash uint64, s *memSeries) { m.unique[hash] = s return } + if m.conflicts == nil { + m.conflicts = make(map[uint64][]*memSeries) + } l := m.conflicts[hash] for i, prev := range l { if labels.Equal(prev.lset, s.lset) { @@ -1786,7 +1789,7 @@ func newStripeSeries(stripeSize int, seriesCallback SeriesLifecycleCallback) *st for i := range s.hashes { s.hashes[i] = seriesHashmap{ unique: map[uint64]*memSeries{}, - conflicts: map[uint64][]*memSeries{}, + conflicts: nil, // Initialized on demand in set(). } } return s