mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 23:42:23 +00:00
*: use clear() to clear maps
Supposedly more efficient since we can avoid some memory management dances. Memory pool agrees: goos: linux goarch: amd64 pkg: github.com/nspcc-dev/neo-go/pkg/core/mempool cpu: AMD Ryzen 7 PRO 7840U w/ Radeon 780M Graphics │ pool.old │ pool.new │ │ sec/op │ sec/op vs base │ Pool/one,_incr_fee-16 12.44m ± 1% 12.51m ± 1% +0.55% (p=0.029 n=10) Pool/many,_same_fee-16 4.960m ± 2% 3.100m ± 1% -37.50% (p=0.000 n=10) Pool/many,_incr_fee-16 16.03m ± 2% 14.11m ± 1% -12.00% (p=0.000 n=10) Pool/one,_same_fee-16 1.742m ± 1% geomean 9.964m 5.556m -17.92% │ pool.old │ pool.new │ │ B/op │ B/op vs base │ Pool/one,_incr_fee-16 8.117Ki ± 120% 7.101Ki ± 128% -12.52% (p=0.022 n=10) Pool/many,_same_fee-16 3941.2Ki ± 0% 805.4Ki ± 0% -79.56% (p=0.000 n=10) Pool/many,_incr_fee-16 3936.2Ki ± 0% 829.8Ki ± 0% -78.92% (p=0.000 n=10) Pool/one,_same_fee-16 12.98Ki ± 10% geomean 501.2Ki 88.59Ki -66.47% │ pool.old │ pool.new │ │ allocs/op │ allocs/op vs base │ Pool/one,_incr_fee-16 28.00 ± 21% 24.00 ± 21% -14.29% (p=0.002 n=10) Pool/many,_same_fee-16 40.38k ± 0% 40.03k ± 0% -0.86% (p=0.000 n=10) Pool/many,_incr_fee-16 40.38k ± 0% 40.04k ± 0% -0.85% (p=0.000 n=10) Pool/one,_same_fee-16 23.00 ± 4% geomean 3.574k 969.8 -5.55% Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
c2a374541f
commit
d9ee31fb52
3 changed files with 4 additions and 6 deletions
|
@ -351,8 +351,8 @@ func (mp *Pool) RemoveStale(isOK func(*transaction.Transaction) bool, feer Feer)
|
|||
// We can reuse already allocated slice
|
||||
// because items are iterated one-by-one in increasing order.
|
||||
newVerifiedTxes := mp.verifiedTxes[:0]
|
||||
mp.fees = make(map[util.Uint160]utilityBalanceAndFees) // it'd be nice to reuse existing map, but we can't easily clear it
|
||||
mp.conflicts = make(map[util.Uint256][]util.Uint256)
|
||||
clear(mp.fees)
|
||||
clear(mp.conflicts)
|
||||
height := feer.BlockHeight()
|
||||
var (
|
||||
staleItems []item
|
||||
|
|
|
@ -543,7 +543,7 @@ func (t *Trie) Collapse(depth int) {
|
|||
panic("negative depth")
|
||||
}
|
||||
t.root = collapse(depth, t.root)
|
||||
t.refcount = make(map[util.Uint256]*cachedNode)
|
||||
clear(t.refcount)
|
||||
}
|
||||
|
||||
func collapse(depth int, node Node) Node {
|
||||
|
|
|
@ -133,9 +133,7 @@ func (w *SerializationContext) Serialize(item Item, protected bool) ([]byte, err
|
|||
if w.data != nil {
|
||||
w.data = w.data[:0]
|
||||
}
|
||||
for k := range w.seen {
|
||||
delete(w.seen, k)
|
||||
}
|
||||
clear(w.seen)
|
||||
err := w.serialize(item)
|
||||
if err != nil && protected {
|
||||
if w.data == nil {
|
||||
|
|
Loading…
Reference in a new issue