From 2bb24fa3faef33b8f74ecb1c69c3e8e8f7f7ab77 Mon Sep 17 00:00:00 2001 From: Delweng Date: Fri, 25 Jul 2025 00:09:54 +0800 Subject: [PATCH] set different cache size Signed-off-by: Delweng --- triedb/pathdb/database.go | 10 +++++++--- triedb/pathdb/history_reader.go | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/triedb/pathdb/database.go b/triedb/pathdb/database.go index 6e405cbe9a..535584aafc 100644 --- a/triedb/pathdb/database.go +++ b/triedb/pathdb/database.go @@ -61,8 +61,12 @@ var ( // maxDiffLayers is the maximum diff layers allowed in the layer tree. maxDiffLayers = 128 - // historyCacheSize is the maximum size of history cache. - historyCacheSize = 4096 + // historyIndexCacheSize is the maximum count of history index cache. + // Each indexBlockDesc is 14bytes, assume each account has 10 descriptors, + // then the total memory usage is ~54MB. + historyIndexCacheSize = 409600 + // historyBlockCacheSize is the maximum count of history block cache. + historyBlockCacheSize = 4096 ) // layer is the interface implemented by all state layers which includes some @@ -246,7 +250,7 @@ func New(diskdb ethdb.Database, config *Config, isVerkle bool) *Database { config: config, diskdb: diskdb, hasher: merkleNodeHasher, - cacher: newHistoryCacher(historyCacheSize), + cacher: newHistoryCacher(historyIndexCacheSize, historyBlockCacheSize), } // Establish a dedicated database namespace tailored for verkle-specific // data, ensuring the isolation of both verkle and merkle tree data. It's diff --git a/triedb/pathdb/history_reader.go b/triedb/pathdb/history_reader.go index 0d9bac1965..e9f00e91ec 100644 --- a/triedb/pathdb/history_reader.go +++ b/triedb/pathdb/history_reader.go @@ -198,10 +198,10 @@ type historyCacher struct { } // newHistoryCacher creates a new historyCacher instance. -func newHistoryCacher(size int) *historyCacher { +func newHistoryCacher(indexSize, blockSize int) *historyCacher { return &historyCacher{ - index: lru.NewCache[string, []byte](size), - block: lru.NewCache[string, []byte](size), + index: lru.NewCache[string, []byte](indexSize), + block: lru.NewCache[string, []byte](blockSize), } }