set different cache size

Signed-off-by: Delweng <delweng@gmail.com>
This commit is contained in:
Delweng 2025-07-25 00:09:54 +08:00 committed by jsvisa
parent fcb657fff4
commit 2bb24fa3fa
2 changed files with 10 additions and 6 deletions

View file

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

View file

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