mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
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:
parent
2e5cd21edf
commit
c7dcdf29b8
1 changed files with 4 additions and 4 deletions
|
|
@ -425,11 +425,11 @@ func (r *mapRenderer) writeFinishedMaps(pauseCb func() bool) error {
|
||||||
r.f.setRange(batch, r.f.indexedView, tempRange, true)
|
r.f.setRange(batch, r.f.indexedView, tempRange, true)
|
||||||
}
|
}
|
||||||
// add or update filter rows
|
// 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++ {
|
for rowIndex := uint32(0); rowIndex < r.f.mapHeight; rowIndex++ {
|
||||||
var (
|
mapIndices := make([]uint32, 0, finishedCount)
|
||||||
mapIndices []uint32
|
rows := make([]FilterRow, 0, finishedCount)
|
||||||
rows []FilterRow
|
|
||||||
)
|
|
||||||
for mapIndex := range r.finished.Iter() {
|
for mapIndex := range r.finished.Iter() {
|
||||||
row := r.finishedMaps[mapIndex].filterMap[rowIndex]
|
row := r.finishedMaps[mapIndex].filterMap[rowIndex]
|
||||||
if fm, _ := r.f.filterMapCache.Get(mapIndex); fm != nil && row.Equal(fm[rowIndex]) {
|
if fm, _ := r.f.filterMapCache.Get(mapIndex); fm != nil && row.Equal(fm[rowIndex]) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue