mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-14 19:01:36 +00:00
core/state/snapshot: preallocate keys and vals slices in proveRange
Preallocate the `keys` and `vals` slices with capacity `max` in `proveRange` to avoid repeated memory allocations during the append loop. This reduces GC pressure in this hot path during state snapshot generation.
This commit is contained in:
parent
e951bcbff7
commit
bd4dbf817c
1 changed files with 2 additions and 2 deletions
|
|
@ -161,8 +161,8 @@ func (result *proofResult) forEach(callback func(key []byte, val []byte) error)
|
||||||
// the error will be returned to abort the entire procedure.
|
// the error will be returned to abort the entire procedure.
|
||||||
func (dl *diskLayer) proveRange(ctx *generatorContext, trieId *trie.ID, prefix []byte, kind string, origin []byte, max int, valueConvertFn func([]byte) ([]byte, error)) (*proofResult, error) {
|
func (dl *diskLayer) proveRange(ctx *generatorContext, trieId *trie.ID, prefix []byte, kind string, origin []byte, max int, valueConvertFn func([]byte) ([]byte, error)) (*proofResult, error) {
|
||||||
var (
|
var (
|
||||||
keys [][]byte
|
keys = make([][]byte, 0, max)
|
||||||
vals [][]byte
|
vals = make([][]byte, 0, max)
|
||||||
proof = rawdb.NewMemoryDatabase()
|
proof = rawdb.NewMemoryDatabase()
|
||||||
diskMore = false
|
diskMore = false
|
||||||
iter = ctx.iterator(kind)
|
iter = ctx.iterator(kind)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue