Skip to content

Commit 1c69408

Browse files
committed
core/rawdb: Fix high memory usage in freezer
The ancients variable in the freezer is a list of hashes, which identifies all of the hashes to be frozen. The slice is being allocated with a capacity of `limit`, which is the number of the last block this batch will attempt to add to the freezer. That means we are allocating memory for all of the blocks in the freezer, not just the ones to be added. If instead we allocate `limit - f.frozen`, we will only allocate enough space for the blocks we're about to add to the freezer. On mainnet this reduces usage by about 320 MB.
1 parent 5435e0d commit 1c69408

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

core/rawdb/freezer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ func (f *freezer) freeze(db ethdb.KeyValueStore) {
311311
var (
312312
start = time.Now()
313313
first = f.frozen
314-
ancients = make([]common.Hash, 0, limit)
314+
ancients = make([]common.Hash, 0, limit-f.frozen)
315315
)
316316
for f.frozen < limit {
317317
// Retrieves all the components of the canonical block

0 commit comments

Comments
 (0)