core: optimize GetVerifiedTransactions()
This simple change improves our BenchmarkTXPerformanceTest by 14%, just because we don't waste time on reallocations during append(). Before: 10000 439754 ns/op 218859 B/op 428 allocs/op ok github.com/CityOfZion/neo-go/integration 5.423s After: 10000 369833 ns/op 87209 B/op 412 allocs/op ok github.com/CityOfZion/neo-go/integration 4.612s
This commit is contained in:
parent
c9257c3de4
commit
e631e75718
1 changed files with 6 additions and 3 deletions
|
@ -269,12 +269,15 @@ func min(sortedPool PoolItems) *PoolItem {
|
||||||
// GetVerifiedTransactions returns a slice of Input from all the transactions in the memory pool
|
// GetVerifiedTransactions returns a slice of Input from all the transactions in the memory pool
|
||||||
// whose hash is not included in excludedHashes.
|
// whose hash is not included in excludedHashes.
|
||||||
func (mp *MemPool) GetVerifiedTransactions() []*transaction.Transaction {
|
func (mp *MemPool) GetVerifiedTransactions() []*transaction.Transaction {
|
||||||
var t []*transaction.Transaction
|
|
||||||
|
|
||||||
mp.lock.RLock()
|
mp.lock.RLock()
|
||||||
defer mp.lock.RUnlock()
|
defer mp.lock.RUnlock()
|
||||||
|
|
||||||
|
var t = make([]*transaction.Transaction, len(mp.unsortedTxn))
|
||||||
|
var i int
|
||||||
|
|
||||||
for _, p := range mp.unsortedTxn {
|
for _, p := range mp.unsortedTxn {
|
||||||
t = append(t, p.txn)
|
t[i] = p.txn
|
||||||
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
return t
|
return t
|
||||||
|
|
Loading…
Reference in a new issue