From cd93a42b5b172759d381975aed2c74c884314589 Mon Sep 17 00:00:00 2001 From: CPerezz Date: Thu, 30 Apr 2026 12:22:20 +0200 Subject: [PATCH] core/state: instrument prefetcher read times --- core/state/reader_eip_7928.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/state/reader_eip_7928.go b/core/state/reader_eip_7928.go index aff5dd3b3b..6c1c63d8c8 100644 --- a/core/state/reader_eip_7928.go +++ b/core/state/reader_eip_7928.go @@ -64,6 +64,8 @@ package state import ( "sync" + "sync/atomic" + "time" "github.com/ethereum/go-ethereum/crypto" @@ -86,6 +88,11 @@ type prefetchStateReader struct { done chan struct{} term chan struct{} closeOnce sync.Once + + // Async-fetch read-time accumulators (atomic because process() runs + // across N goroutines). + accountReadNS atomic.Int64 + storageReadNS atomic.Int64 } func newPrefetchStateReader(reader StateReader, accessList bal.StorageKeys, nThreads int) *prefetchStateReader { @@ -180,9 +187,13 @@ func (r *prefetchStateReader) process(start, limit int) { return default: if j == 0 { + accountReadStart := time.Now() r.StateReader.Account(t.addr) + r.accountReadNS.Add(time.Since(accountReadStart).Nanoseconds()) } else { + storageReadStart := time.Now() r.StateReader.Storage(t.addr, t.slots[j-1]) + r.storageReadNS.Add(time.Since(storageReadStart).Nanoseconds()) } } } @@ -372,3 +383,10 @@ func (r *prefetchStateReader) GetStateStats() StateReaderStats { } return StateReaderStats{} } + +// PrefetchReadTimes returns the accumulated wall-time-of-each-call durations +// for asynchronous account/storage prefetches. Sum-of-CPU-time across worker +// goroutines; not wall-clock total prefetch time. +func (r *prefetchStateReader) PrefetchReadTimes() (account, storage time.Duration) { + return time.Duration(r.accountReadNS.Load()), time.Duration(r.storageReadNS.Load()) +}