mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
rlp: avoid list header allocation in encoder (#21274)
List headers made up 11% of all allocations during sync. This change removes most of those allocations by keeping the list header values cached in the encoder buffer instead. Since encoder buffers are pooled, list headers are no longer allocated in the common case where an encoder buffer is available for reuse. Co-authored-by: Felix Lange <fjl@twurst.com> # Conflicts: # rlp/encode.go
This commit is contained in:
parent
d6f7b4b92c
commit
6eaa9d340b
@ -158,12 +158,8 @@ var encbufPool = sync.Pool{
|
||||
|
||||
func (w *encbuf) reset() {
|
||||
w.lhsize = 0
|
||||
if w.str != nil {
|
||||
w.str = w.str[:0]
|
||||
}
|
||||
if w.lheads != nil {
|
||||
w.lheads = w.lheads[:0]
|
||||
}
|
||||
w.str = w.str[:0]
|
||||
w.lheads = w.lheads[:0]
|
||||
}
|
||||
|
||||
// encbuf implements io.Writer so it can be passed it into EncodeRLP.
|
||||
@ -202,15 +198,16 @@ func (w *encbuf) encodeString(b []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
// list adds a new list header to the header stack. It returns the index
|
||||
// of the header. The caller must call listEnd with this index after encoding
|
||||
// the content of the list.
|
||||
func (w *encbuf) list() int {
|
||||
lh := listhead{offset: len(w.str), size: w.lhsize}
|
||||
idx := len(w.lheads)
|
||||
w.lheads = append(w.lheads, lh)
|
||||
return idx
|
||||
w.lheads = append(w.lheads, listhead{offset: len(w.str), size: w.lhsize})
|
||||
return len(w.lheads) - 1
|
||||
}
|
||||
|
||||
func (w *encbuf) listEnd(idx int) {
|
||||
lh := &w.lheads[idx]
|
||||
func (w *encbuf) listEnd(index int) {
|
||||
lh := &w.lheads[index]
|
||||
lh.size = w.size() - lh.offset - lh.size
|
||||
if lh.size < 56 {
|
||||
w.lhsize++ // length encoded into kind tag
|
||||
|
57
to-merge.txt
57
to-merge.txt
@ -705,60 +705,3 @@ Author: Guillaume Ballet <gballet@gmail.com>
|
||||
Date: Tue Jun 30 15:22:21 2020 +0200
|
||||
|
||||
go.mod: bump gopsutil version (#21275)
|
||||
|
||||
commit ddeea1e0c68df82c1190d3ee71aae87ed3d92bfe
|
||||
Author: Marius van der Wijden <m.vanderwijden@live.de>
|
||||
Date: Tue Jun 30 11:59:06 2020 +0200
|
||||
|
||||
core: types: less allocations when hashing and tx handling (#21265)
|
||||
|
||||
* core, crypto: various allocation savings regarding tx handling
|
||||
|
||||
* core: reduce allocs for gas price comparison
|
||||
|
||||
This change reduces the allocations needed for comparing different transactions to each other.
|
||||
A call to `tx.GasPrice()` copies the gas price as it has to be safe against modifications and
|
||||
also needs to be threadsafe. For comparing and ordering different transactions we don't need
|
||||
these guarantees
|
||||
|
||||
* core: added tx.GasPriceIntCmp for comparison without allocation
|
||||
|
||||
adds a method to remove unneeded allocation in comparison to tx.gasPrice
|
||||
|
||||
* core/types: pool legacykeccak256 objects in rlpHash
|
||||
|
||||
rlpHash is by far the most used function in core that allocates a legacyKeccak256 object on each call.
|
||||
Since it is so widely used it makes sense to add pooling here so we relieve the GC.
|
||||
On my machine these changes result in > 100 MILLION less allocations and > 30 GB less allocated memory.
|
||||
|
||||
* reverted some changes
|
||||
|
||||
* reverted some changes
|
||||
|
||||
* trie: use crypto.KeccakState instead of replicating code
|
||||
|
||||
Co-authored-by: Martin Holst Swende <martin@swende.se>
|
||||
|
||||
commit e376d2fb31a8fa131ab1f6b9f96ac8a41c94e007
|
||||
Author: Martin Holst Swende <martin@swende.se>
|
||||
Date: Tue Jun 30 10:12:51 2020 +0200
|
||||
|
||||
cmd/evm: add state transition tool for testing (#20958)
|
||||
|
||||
This PR implements the EVM state transition tool, which is intended
|
||||
to be the replacement for our retesteth client implementation.
|
||||
Documentation is present in the cmd/evm/README.md file.
|
||||
|
||||
Co-authored-by: Felix Lange <fjl@twurst.com>
|
||||
|
||||
commit dd91c7ce6ab5f140e576caecc8efe8f12ab3a6b1
|
||||
Author: Binacs <bin646891055@gmail.com>
|
||||
Date: Tue Jun 30 15:56:40 2020 +0800
|
||||
|
||||
cmd: abstract `getPassPhrase` functions into one (#21219)
|
||||
|
||||
* [cmd] Abstract `getPassPhrase` functions into one.
|
||||
|
||||
* cmd/ethkey: fix compilation failure
|
||||
|
||||
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
|
||||
|
Loading…
Reference in New Issue
Block a user