-
Notifications
You must be signed in to change notification settings - Fork 21.5k
Open
Description
Seems like during sync the log filter is allocating like crazy. Roughly 12% of all allocations are spent there.
Roughly 5% of these allocations can be reduced with #33006, the others are here around reading receipts. But I wonder why it should take these many allocations, since we only need to read ~20M receipts (one per block) iiuc.
(pprof) list renderCurrentMap
Total: 84321869564
ROUTINE ======================== github.com/ethereum/go-ethereum/core/filtermaps.(*mapRenderer).renderCurrentMap in github.com/ethereum/go-ethereum/core/filtermaps/map_renderer.go
563431146 6419232006 (flat, cum) 7.61% of Total
. . 308:func (r *mapRenderer) renderCurrentMap(stopCb func() bool) (bool, error) {
. . 309: var (
. . 310: totalTime time.Duration
. . 311: logValuesProcessed, blocksProcessed int64
. . 312: )
. . 313: start := time.Now()
. 2088132 314: if !r.iterator.updateChainView(r.f.targetView) {
. . 315: return false, errChainUpdate
. . 316: }
. . 317: var waitCnt int
. . 318:
. . 319: if r.iterator.lvIndex == 0 {
. . 320: r.currentMap.blockLvPtrs = []uint64{0}
. . 321: }
. . 322: type lvPos struct{ rowIndex, layerIndex uint32 }
. 114691 323: rowMappingCache := lru.NewCache[common.Hash, lvPos](cachedRowMappings)
. . 324: defer rowMappingCache.Purge()
. . 325:
. . 326: for r.iterator.lvIndex < uint64(r.currentMap.mapIndex+1)<<r.f.logValuesPerMap && !r.iterator.finished {
. . 327: waitCnt++
. . 328: if waitCnt >= valuesPerCallback {
. . 329: totalTime += time.Since(start)
. . 330: if stopCb() {
. . 331: return false, nil
. . 332: }
. . 333: start = time.Now()
. 114562886 334: if !r.iterator.updateChainView(r.f.targetView) {
. . 335: return false, errChainUpdate
. . 336: }
. . 337: waitCnt = 0
. . 338: }
. . 339: if logValue := r.iterator.getValueHash(); logValue != (common.Hash{}) {
. . 340: lvp, cached := rowMappingCache.Get(logValue)
. . 341: if !cached {
. . 342: lvp = lvPos{rowIndex: r.f.rowIndex(r.currentMap.mapIndex, 0, logValue)}
. . 343: }
. . 344: for uint32(len(r.currentMap.filterMap[lvp.rowIndex])) >= r.f.maxRowLength(lvp.layerIndex) {
. . 345: lvp.layerIndex++
. . 346: lvp.rowIndex = r.f.rowIndex(r.currentMap.mapIndex, lvp.layerIndex, logValue)
. . 347: cached = false
. . 348: }
563178175 563178175 349: r.currentMap.filterMap[lvp.rowIndex] = append(r.currentMap.filterMap[lvp.rowIndex], r.f.columnIndex(r.iterator.lvIndex, &logValue))
. . 350: if !cached {
. 468754938 351: rowMappingCache.Add(logValue, lvp)
. . 352: }
. . 353: }
. 5269320820 354: if err := r.iterator.next(); err != nil {
. . 355: return false, fmt.Errorf("failed to advance log iterator at %d while rendering map %d: %v", r.iterator.lvIndex, r.currentMap.mapIndex, err)
. . 356: }
. . 357: if !r.iterator.skipToBoundary {
. . 358: logValuesProcessed++
. . 359: r.currentMap.lastBlock = r.iterator.blockNumber
. . 360: if r.iterator.blockStart {
. . 361: blocksProcessed++
252971 252971 362: r.currentMap.blockLvPtrs = append(r.currentMap.blockLvPtrs, r.iterator.lvIndex)
. . 363: }
. . 364: if !r.f.testDisableSnapshots && r.renderBefore >= r.f.indexedRange.maps.AfterLast() &&
. . 365: (r.iterator.delimiter || r.iterator.finished) {
. . 366: r.makeSnapshot()
. . 367: }
. . 368: }
. . 369: }
. . 370: if r.iterator.finished {
. . 371: r.currentMap.finished = true
. . 372: r.currentMap.headDelimiter = r.iterator.lvIndex
. . 373: }
. 959393 374: r.currentMap.lastBlockId = r.f.targetView.BlockId(r.currentMap.lastBlock)
. . 375: totalTime += time.Since(start)
. . 376: mapRenderTimer.Update(totalTime)
. . 377: mapLogValueMeter.Mark(logValuesProcessed)
. . 378: mapBlockMeter.Mark(blocksProcessed)
. . 379: return true, nil
Metadata
Metadata
Assignees
Labels
No labels