From bd4dbf817c2a58b3e26aa4666bdc7aa3646f48ce Mon Sep 17 00:00:00 2001 From: Tanvir Date: Wed, 25 Mar 2026 01:37:52 +0800 Subject: [PATCH] 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. --- core/state/snapshot/generate.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/state/snapshot/generate.go b/core/state/snapshot/generate.go index 01fb55ea4c..655dcf6c73 100644 --- a/core/state/snapshot/generate.go +++ b/core/state/snapshot/generate.go @@ -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)