Skip to content

Commit

Permalink
Slight optimization to processOrphans to prevent reallocations
Browse files Browse the repository at this point in the history
  • Loading branch information
zquestz committed Dec 26, 2024
1 parent f389db5 commit 12651ee
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions blockchain/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,12 @@ func (b *BlockChain) blockExists(hash *chainhash.Hash) (bool, error) {
//
// This function MUST be called with the chain state lock held (for writes).
func (b *BlockChain) processOrphans(hash *chainhash.Hash, flags BehaviorFlags) error {
// Start with processing at least the passed hash. Leave a little room
// for additional orphan blocks that need to be processed without
// needing to grow the array in the common case.
processHashes := make([]*chainhash.Hash, 0, 10)
// Start with processing at least the passed hash.
var processHashes []*chainhash.Hash
processHashes = append(processHashes, hash)
for len(processHashes) > 0 {
// Pop the first hash to process from the slice.
processHash := processHashes[0]
processHashes[0] = nil // Prevent GC leak.
processHashes = processHashes[1:]
processHash := processHashes[len(processHashes)-1]
processHashes = processHashes[:len(processHashes)-1]

// Look up all orphans that are parented by the block we just
// accepted. This will typically only be one, but it could
Expand Down

0 comments on commit 12651ee

Please sign in to comment.