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:
Tanvir 2026-03-25 01:37:52 +08:00
parent e951bcbff7
commit bd4dbf817c

View file

@ -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)