Skip to content

Commit

Permalink
try live copy first
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-ogrady committed Nov 21, 2023
1 parent 4fc35d9 commit 0209e1c
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions core/state/trie_prefetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,20 +509,29 @@ func (to *trieOrchestrator) processTasks() {
// Enqueue more work as soon as trie copies are available
lt := len(tasks)
for i := 0; i < lt; i++ {
// Wait for an available copy or create one
// Try to create to get an active copy first
var t Trie
select {
case t = <-to.copyChan:
case to.copySpawner <- struct{}{}:
to.copies++
t = to.copyBase()
case <-to.stop:
remainingCount := len(tasks[i:])
to.taskLock.Lock()
to.skips += remainingCount
to.taskLock.Unlock()
to.processingTasks.Add(-remainingCount)
return
default:
}

// Wait for an available copy or create one, if we weren't
// able to get a previously created copy
if t == nil {
select {
case t = <-to.copyChan:
case to.copySpawner <- struct{}{}:
to.copies++
t = to.copyBase()
case <-to.stop:
remainingCount := len(tasks[i:])
to.taskLock.Lock()
to.skips += remainingCount
to.taskLock.Unlock()
to.processingTasks.Add(-remainingCount)
return
}
}

// Enqueue work, unless stopped.
Expand Down

0 comments on commit 0209e1c

Please sign in to comment.