Skip to content
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

trie, triedb/pathdb: prealloc capacity for map and slice #29986

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Changes from 1 commit
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
16 changes: 9 additions & 7 deletions triedb/pathdb/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,13 @@ func (r *decoder) readAccount(pos int) (accountIndex, []byte, error) {
// readStorage parses the storage slots from the byte stream with specified account.
func (r *decoder) readStorage(accIndex accountIndex) ([]common.Hash, map[common.Hash][]byte, error) {
var (
last common.Hash
list []common.Hash
storage = make(map[common.Hash][]byte)
count = int(accIndex.storageSlots)
list = make([]common.Hash, 0, count)
storage = make(map[common.Hash][]byte, count)
)
for j := 0; j < int(accIndex.storageSlots); j++ {
for j := 0; j < count; j++ {
var (
last common.Hash
mask-pp marked this conversation as resolved.
Show resolved Hide resolved
index slotIndex
start = (accIndex.storageOffset + uint32(j)) * uint32(slotIndexSize)
end = (accIndex.storageOffset + uint32(j+1)) * uint32(slotIndexSize)
Expand Down Expand Up @@ -430,9 +431,10 @@ func (r *decoder) readStorage(accIndex accountIndex) ([]common.Hash, map[common.
// decode deserializes the account and storage data from the provided byte stream.
func (h *history) decode(accountData, storageData, accountIndexes, storageIndexes []byte) error {
var (
accounts = make(map[common.Address][]byte)
count = len(accountIndexes) / accountIndexSize
accounts = make(map[common.Address][]byte, count)
storages = make(map[common.Address]map[common.Hash][]byte)
accountList []common.Address
accountList = make([]common.Address, 0, count)
storageList = make(map[common.Address][]common.Hash)

r = &decoder{
Expand All @@ -445,7 +447,7 @@ func (h *history) decode(accountData, storageData, accountIndexes, storageIndexe
if err := r.verify(); err != nil {
return err
}
for i := 0; i < len(accountIndexes)/accountIndexSize; i++ {
for i := 0; i < count; i++ {
// Resolve account first
accIndex, accData, err := r.readAccount(i)
if err != nil {
Expand Down