mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-12 09:51: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.
|
||||
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 (
|
||||
keys [][]byte
|
||||
vals [][]byte
|
||||
keys = make([][]byte, 0, max)
|
||||
vals = make([][]byte, 0, max)
|
||||
proof = rawdb.NewMemoryDatabase()
|
||||
diskMore = false
|
||||
iter = ctx.iterator(kind)
|
||||
|
|
|
|||
Loading…
Reference in a new issue