Skip to content

Commit b8ac4ba

Browse files
authored
ledger: refactor maxPaysetHint -> avarageEncodedTxnSizeHint (#3162)
## Summary This refactoring would eliminate the need to change the maxPaysetHint while we modify the block size. ## Test Plan Use existing tests.
1 parent 9ca31f8 commit b8ac4ba

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

ledger/internal/eval.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ type LedgerForCowBase interface {
4848
// ErrRoundZero is self-explanatory
4949
var ErrRoundZero = errors.New("cannot start evaluator for round 0")
5050

51-
// maxPaysetHint makes sure that we don't allocate too much memory up front
52-
// in the block evaluator, since there cannot reasonably be more than this
53-
// many transactions in a block.
54-
const maxPaysetHint = 20000
51+
// averageEncodedTxnSizeHint is an estimation for the encoded transaction size
52+
// which is used for preallocating memory upfront in the payset. Preallocating
53+
// helps to avoid re-allocating storage during the evaluation/validation which
54+
// is considerably slower.
55+
const averageEncodedTxnSizeHint = 150
5556

5657
// asyncAccountLoadingThreadCount controls how many go routines would be used
5758
// to load the account data before the Eval() start processing individual
@@ -481,6 +482,7 @@ func StartEvaluator(l LedgerForEvaluator, hdr bookkeeping.BlockHeader, evalOpts
481482
// Preallocate space for the payset so that we don't have to
482483
// dynamically grow a slice (if evaluating a whole block).
483484
if evalOpts.PaysetHint > 0 {
485+
maxPaysetHint := evalOpts.MaxTxnBytesPerBlock / averageEncodedTxnSizeHint
484486
if evalOpts.PaysetHint > maxPaysetHint {
485487
evalOpts.PaysetHint = maxPaysetHint
486488
}

0 commit comments

Comments
 (0)