mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 21:26:42 +00:00
core/filtermaps: optimize getFilterMapRowsOfGroup
This commit is contained in:
parent
6924eeaee0
commit
ff185db96d
1 changed files with 33 additions and 10 deletions
|
|
@ -600,27 +600,50 @@ func (f *FilterMaps) getFilterMapRows(mapIndices []uint32, rowIndex uint32, base
|
||||||
// getFilterMapRowsOfGroup fetches a set of filter map rows at map indices
|
// getFilterMapRowsOfGroup fetches a set of filter map rows at map indices
|
||||||
// belonging to the same base row group.
|
// belonging to the same base row group.
|
||||||
func (f *FilterMaps) getFilterMapRowsOfGroup(target []FilterRow, mapIndices []uint32, rowIndex uint32, baseLayerOnly bool) error {
|
func (f *FilterMaps) getFilterMapRowsOfGroup(target []FilterRow, mapIndices []uint32, rowIndex uint32, baseLayerOnly bool) error {
|
||||||
var (
|
if len(mapIndices) == 0 {
|
||||||
groupIndex = f.mapGroupIndex(mapIndices[0])
|
return nil
|
||||||
mapRowIndex = f.mapRowIndex(groupIndex, rowIndex)
|
}
|
||||||
)
|
|
||||||
|
groupIndex := f.mapGroupIndex(mapIndices[0])
|
||||||
|
mapRowIndex := f.mapRowIndex(groupIndex, rowIndex)
|
||||||
|
|
||||||
|
// Validate all indices belong to the same group before database access
|
||||||
|
for _, mapIndex := range mapIndices {
|
||||||
|
if f.mapGroupIndex(mapIndex) != groupIndex {
|
||||||
|
return fmt.Errorf("maps are not in the same base row group, index: %d, group: %d", mapIndex, groupIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
baseRows, err := rawdb.ReadFilterMapBaseRows(f.db, mapRowIndex, f.baseRowGroupSize, f.logMapWidth)
|
baseRows, err := rawdb.ReadFilterMapBaseRows(f.db, mapRowIndex, f.baseRowGroupSize, f.logMapWidth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to retrieve base row group %d of row %d: %v", groupIndex, rowIndex, err)
|
return fmt.Errorf("failed to retrieve base row group %d of row %d: %v", groupIndex, rowIndex, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process base layer rows
|
||||||
for i, mapIndex := range mapIndices {
|
for i, mapIndex := range mapIndices {
|
||||||
if f.mapGroupIndex(mapIndex) != groupIndex {
|
|
||||||
return fmt.Errorf("maps are not in the same base row group, index: %d, group: %d", mapIndex, groupIndex)
|
|
||||||
}
|
|
||||||
row := baseRows[f.mapGroupOffset(mapIndex)]
|
row := baseRows[f.mapGroupOffset(mapIndex)]
|
||||||
|
target[i] = row
|
||||||
|
}
|
||||||
|
|
||||||
|
// Batch process extended rows if needed
|
||||||
if !baseLayerOnly {
|
if !baseLayerOnly {
|
||||||
|
for i, mapIndex := range mapIndices {
|
||||||
extRow, err := rawdb.ReadFilterMapExtRow(f.db, f.mapRowIndex(mapIndex, rowIndex), f.logMapWidth)
|
extRow, err := rawdb.ReadFilterMapExtRow(f.db, f.mapRowIndex(mapIndex, rowIndex), f.logMapWidth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to retrieve filter map %d extended row %d: %v", mapIndex, rowIndex, err)
|
return fmt.Errorf("failed to retrieve filter map %d extended row %d: %v", mapIndex, rowIndex, err)
|
||||||
}
|
}
|
||||||
row = append(row, extRow...)
|
if len(extRow) > 0 {
|
||||||
|
// Use append with pre-calculated capacity if possible
|
||||||
|
baseRow := target[i]
|
||||||
|
if cap(baseRow)-len(baseRow) >= len(extRow) {
|
||||||
|
target[i] = append(baseRow, extRow...)
|
||||||
|
} else {
|
||||||
|
newRow := make(FilterRow, len(baseRow), len(baseRow)+len(extRow))
|
||||||
|
copy(newRow, baseRow)
|
||||||
|
target[i] = append(newRow, extRow...)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
target[i] = row
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue