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
This commit is contained in:
madisoncarter1234 2025-12-21 13:44:11 -05:00
parent 2e5cd21edf
commit c7dcdf29b8

View file

@ -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]) {