allegro / allegro/bigcache

Optimize map capacity allocation during shard initialization.

オープン
#419 コメント 2 件 リアクション 1 件 担当者 0 名 GitHub で見る
主要言語
Go
スター
8.2k
フォーク
614
平均マージ
5日 12時間
マージ済み PR(30日)
1

説明

If StatsEnabled is configured as false, could we consider not allocating a ShardSize size for hashmapStats during the Shard initialization function (initNewShard)? This is because the data is not used in subsequent processes, resulting in the allocation of invalid memory space. This issue is more pronounced when caching a large number of entries.
```
func initNewShard(config Config, callback onRemoveCallback, clock clock) *cacheShard {
bytesQueueInitialCapacity := config.initialShardSize() * config.MaxEntrySize
maximumShardSizeInBytes := config.maximumShardSizeInBytes()
if maximumShardSizeInBytes > 0 && bytesQueueInitialCapacity > maximumShardSizeInBytes {
bytesQueueInitialCapacity = maximumShardSizeInBytes
}
return &cacheShard{
hashmap: make(map[uint64]uint64, config.initialShardSize()),
// if StatsEnabled==false,Only make(map[uint64]uint32)
hashmapStats: make(map[uint64]uint32, config.initialShardSize()),
entries: *queue.NewBytesQueue(bytesQueueInitialCapacity, maximumShardSizeInBytes, config.Verbose),
entryBuffer: make([]byte, config.MaxEntrySize+headersSizeInBytes),
onRemove: callback,
isVerbose: config.Verbose,
logger: newLogger(config.Logger),
clock: clock,
lifeWindow: uint64(config.LifeWindow.Seconds()),
statsEnabled: config.StatsEnabled,
cleanEnabled: config.CleanWindow > 0,
}
}
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。