mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
core: optimize using sync.Pool
This commit is contained in:
parent
de5ea2ffd8
commit
36874824b1
1 changed files with 10 additions and 1 deletions
|
|
@ -46,6 +46,12 @@ type txSenderCacherRequest struct {
|
||||||
inc int
|
inc int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var txSenderCacherRequestPool = sync.Pool{
|
||||||
|
New: func() any {
|
||||||
|
return &txSenderCacherRequest{}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// txSenderCacher is a helper structure to concurrently ecrecover transaction
|
// txSenderCacher is a helper structure to concurrently ecrecover transaction
|
||||||
// senders from digital signatures on background threads.
|
// senders from digital signatures on background threads.
|
||||||
type txSenderCacher struct {
|
type txSenderCacher struct {
|
||||||
|
|
@ -73,6 +79,7 @@ func (cacher *txSenderCacher) cache() {
|
||||||
for i := 0; i < len(task.txs); i += task.inc {
|
for i := 0; i < len(task.txs); i += task.inc {
|
||||||
types.Sender(task.signer, task.txs[i])
|
types.Sender(task.signer, task.txs[i])
|
||||||
}
|
}
|
||||||
|
txSenderCacherRequestPool.Put(task)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,11 +97,13 @@ func (cacher *txSenderCacher) Recover(signer types.Signer, txs []*types.Transact
|
||||||
tasks = (len(txs) + 3) / 4
|
tasks = (len(txs) + 3) / 4
|
||||||
}
|
}
|
||||||
for i := 0; i < tasks; i++ {
|
for i := 0; i < tasks; i++ {
|
||||||
cacher.tasks <- &txSenderCacherRequest{
|
req := txSenderCacherRequestPool.Get().(*txSenderCacherRequest)
|
||||||
|
*req = txSenderCacherRequest{
|
||||||
signer: signer,
|
signer: signer,
|
||||||
txs: txs[i:],
|
txs: txs[i:],
|
||||||
inc: tasks,
|
inc: tasks,
|
||||||
}
|
}
|
||||||
|
cacher.tasks <- req
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue