From c7dcdf29b8748352f82e4695cd517dc8635b7ee1 Mon Sep 17 00:00:00 2001 From: madisoncarter1234 Date: Sun, 21 Dec 2025 13:44:11 -0500 Subject: [PATCH] core/filtermaps: pre-allocate slices in writeFinishedMaps Pre-allocate mapIndices and rows slices with capacity before the inner loop to avoid repeated slice growth allocations. This reduces allocations during log index rendering, particularly when writing finished maps to the database. The slices are rebuilt for every row (mapHeight iterations), so pre-allocating with the known capacity (number of finished maps) significantly reduces memory pressure. Fixes #33040 --- core/filtermaps/map_renderer.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/filtermaps/map_renderer.go b/core/filtermaps/map_renderer.go index e1284a3829..2acc2af1d4 100644 --- a/core/filtermaps/map_renderer.go +++ b/core/filtermaps/map_renderer.go @@ -425,11 +425,11 @@ func (r *mapRenderer) writeFinishedMaps(pauseCb func() bool) error { r.f.setRange(batch, r.f.indexedView, tempRange, true) } // add or update filter rows + // Pre-allocate slices to avoid repeated allocations during append + finishedCount := r.finished.Count() for rowIndex := uint32(0); rowIndex < r.f.mapHeight; rowIndex++ { - var ( - mapIndices []uint32 - rows []FilterRow - ) + mapIndices := make([]uint32, 0, finishedCount) + rows := make([]FilterRow, 0, finishedCount) for mapIndex := range r.finished.Iter() { row := r.finishedMaps[mapIndex].filterMap[rowIndex] if fm, _ := r.f.filterMapCache.Get(mapIndex); fm != nil && row.Equal(fm[rowIndex]) {