Skip to content

Commit

Permalink
performance: flush pending write caches at the beginning of Eval()
Browse files Browse the repository at this point in the history
  • Loading branch information
icorderi committed Oct 24, 2022
1 parent ae00e10 commit 02dccd7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ledger/acctupdates.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,8 @@ type accountUpdatesLedgerEvaluator struct {
prevHeader bookkeeping.BlockHeader
}

func (l *accountUpdatesLedgerEvaluator) FlushCaches() {}

// GenesisHash returns the genesis hash
func (aul *accountUpdatesLedgerEvaluator) GenesisHash() crypto.Digest {
return aul.au.ledger.GenesisHash()
Expand Down
2 changes: 2 additions & 0 deletions ledger/evalindexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ type indexerLedgerConnector struct {
roundResources EvalForIndexerResources
}

func (l indexerLedgerConnector) FlushCaches() {}

// BlockHdr is part of LedgerForEvaluator interface.
func (l indexerLedgerConnector) BlockHdr(round basics.Round) (bookkeeping.BlockHeader, error) {
if round != l.latestRound {
Expand Down
4 changes: 4 additions & 0 deletions ledger/internal/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ type LedgerForEvaluator interface {
GenesisProto() config.ConsensusParams
LatestTotals() (basics.Round, ledgercore.AccountTotals, error)
VotersForStateProof(basics.Round) (*ledgercore.VotersForRound, error)
FlushCaches()
}

// EvaluatorOptions defines the evaluator creation options
Expand Down Expand Up @@ -1491,6 +1492,9 @@ func (validator *evalTxValidator) run() {
// AddBlock: Eval(context.Background(), l, blk, false, txcache, nil)
// tracker: Eval(context.Background(), l, blk, false, txcache, nil)
func Eval(ctx context.Context, l LedgerForEvaluator, blk bookkeeping.Block, validate bool, txcache verify.VerifiedTransactionCache, executionPool execpool.BacklogPool) (ledgercore.StateDelta, error) {
// flush the pending writes in the cache to make everything read so far available during eval
l.FlushCaches()

eval, err := StartEvaluator(l, blk.BlockHeader,
EvaluatorOptions{
PaysetHint: len(blk.Payset),
Expand Down
2 changes: 2 additions & 0 deletions ledger/internal/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ func (ledger *evalTestLedger) StartEvaluator(hdr bookkeeping.BlockHeader, payset
})
}

func (l *evalTestLedger) FlushCaches() {}

// GetCreatorForRound takes a CreatableIndex and a CreatableType and tries to
// look up a creator address, setting ok to false if the query succeeded but no
// creator was found.
Expand Down
1 change: 1 addition & 0 deletions ledger/internal/prefetcher/prefetcher_alignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (l *prefetcherAlignmentTestLedger) LatestTotals() (basics.Round, ledgercore
func (l *prefetcherAlignmentTestLedger) VotersForStateProof(basics.Round) (*ledgercore.VotersForRound, error) {
return nil, nil
}
func (l *prefetcherAlignmentTestLedger) FlushCaches() {}

func parseLoadedAccountDataEntries(loadedAccountDataEntries []prefetcher.LoadedAccountDataEntry) map[basics.Address]struct{} {
if len(loadedAccountDataEntries) == 0 {
Expand Down
9 changes: 9 additions & 0 deletions ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,15 @@ func (l *Ledger) StartEvaluator(hdr bookkeeping.BlockHeader, paysetHint, maxTxnB
})
}

func (l *Ledger) FlushCaches() {
l.accts.accountsMu.Lock()

l.accts.baseAccounts.flushPendingWrites()
l.accts.baseResources.flushPendingWrites()

l.accts.accountsMu.Unlock()
}

// Validate uses the ledger to validate block blk as a candidate next block.
// It returns an error if blk is not the expected next block, or if blk is
// not a valid block (e.g., it has duplicate transactions, overspends some
Expand Down

0 comments on commit 02dccd7

Please sign in to comment.