Skip to content

triedb: opt using sync.Pool #32375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions triedb/pathdb/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ func (l *lookup) storageTip(accountHash common.Hash, slotHash common.Hash, state
return common.Hash{}
}

var listPool = sync.Pool{
New: func() any {
return make([]common.Hash, 0, 16)
},
}

// addLayer traverses the state data retained in the specified diff layer and
// integrates it into the lookup set.
//
Expand All @@ -182,7 +188,7 @@ func (l *lookup) addLayer(diff *diffLayer) {
for accountHash := range diff.states.accountData {
list, exists := l.accounts[accountHash]
if !exists {
list = make([]common.Hash, 0, 16) // TODO(rjl493456442) use sync pool
list = listPool.Get().([]common.Hash)
}
list = append(list, state)
l.accounts[accountHash] = list
Expand All @@ -197,7 +203,7 @@ func (l *lookup) addLayer(diff *diffLayer) {
key := storageKey(accountHash, slotHash)
list, exists := l.storages[key]
if !exists {
list = make([]common.Hash, 0, 16) // TODO(rjl493456442) use sync pool
list = listPool.Get().([]common.Hash)
}
list = append(list, state)
l.storages[key] = list
Expand Down Expand Up @@ -251,6 +257,7 @@ func (l *lookup) removeLayer(diff *diffLayer) error {
if len(list) != 0 {
l.accounts[accountHash] = list
} else {
listPool.Put(list[:0])
delete(l.accounts, accountHash)
}
}
Expand All @@ -268,6 +275,7 @@ func (l *lookup) removeLayer(diff *diffLayer) error {
if len(list) != 0 {
l.storages[key] = list
} else {
listPool.Put(list[:0])
delete(l.storages, key)
}
}
Expand Down