Skip to content

Commit

Permalink
Decrease number of map allocations in block processing
Browse files Browse the repository at this point in the history
  • Loading branch information
zquestz committed Dec 26, 2024
1 parent bd3a227 commit 30ba011
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion blockchain/utxoviewpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (view *UtxoViewpoint) addInputUtxos(source utxoView, block *bchutil.Block,
// Build a map of in-flight transactions because some of the inputs in
// this block could be referencing other transactions earlier in this
// block which are not yet in the chain.
txInFlight := map[chainhash.Hash]int{}
txInFlight := make(map[chainhash.Hash]int, len(block.Transactions()))
transactions := block.Transactions()
for i, tx := range transactions {
txInFlight[*tx.Hash()] = i
Expand Down
4 changes: 2 additions & 2 deletions blockchain/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func CheckTransactionSanity(tx *bchutil.Tx, magneticAnomalyActive bool, upgrade9
}

// Check for duplicate transaction inputs.
existingTxOut := make(map[wire.OutPoint]struct{})
existingTxOut := make(map[wire.OutPoint]struct{}, len(msgTx.TxIn))
for _, txIn := range msgTx.TxIn {
if _, exists := existingTxOut[txIn.PreviousOutPoint]; exists {
return ruleError(ErrDuplicateTxInputs, "transaction "+
Expand Down Expand Up @@ -518,7 +518,7 @@ func checkBlockSanity(block *bchutil.Block, powLimit *big.Int, timeSource Median
// Check for duplicate transactions. This check will be fairly quick
// since the transaction hashes are already cached due to building the
// merkle tree above.
existingTxHashes := make(map[chainhash.Hash]struct{})
existingTxHashes := make(map[chainhash.Hash]struct{}, len(transactions))
for _, tx := range transactions {
hash := tx.Hash()
if _, exists := existingTxHashes[*hash]; exists {
Expand Down

0 comments on commit 30ba011

Please sign in to comment.