mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
trie: use a scratchspace for path
goos: linux
goarch: amd64
pkg: github.com/ethereum/go-ethereum/trie
cpu: 12th Gen Intel(R) Core(TM) i7-1270P
│ stacktrie.3 │ stacktrie.4 │
│ sec/op │ sec/op vs base │
Insert100K-8 69.50m ± 12% 74.59m ± 14% ~ (p=0.128 n=7)
│ stacktrie.3 │ stacktrie.4 │
│ B/op │ B/op vs base │
Insert100K-8 4.640Mi ± 0% 3.112Mi ± 0% -32.93% (p=0.001 n=7)
│ stacktrie.3 │ stacktrie.4 │
│ allocs/op │ allocs/op vs base │
Insert100K-8 226.7k ± 0% 126.7k ± 0% -44.11% (p=0.001 n=7)
This commit is contained in:
parent
4eb7032c97
commit
0323853ada
1 changed files with 8 additions and 5 deletions
|
|
@ -49,6 +49,7 @@ type StackTrie struct {
|
|||
onTrieNode OnTrieNode
|
||||
|
||||
keyScratch []byte
|
||||
pathScratch []byte
|
||||
}
|
||||
|
||||
// NewStackTrie allocates and initializes an empty trie. The committed nodes
|
||||
|
|
@ -58,6 +59,8 @@ func NewStackTrie(onTrieNode OnTrieNode) *StackTrie {
|
|||
root: stPool.Get().(*stNode),
|
||||
h: newHasher(false),
|
||||
onTrieNode: onTrieNode,
|
||||
keyScratch: make([]byte, 0, 32),
|
||||
pathScratch: make([]byte, 0, 32),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +89,7 @@ func (t *StackTrie) Update(key, value []byte) error {
|
|||
} else {
|
||||
t.last = append(t.last[:0], k...) // reuse key slice
|
||||
}
|
||||
t.insert(t.root, k, value, nil)
|
||||
t.insert(t.root, k, value, t.pathScratch[:0])
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue