Optimize map capacity allocation during shard initialization.
- Vorherrschende Sprache
- Go
- Sterne
- 8.2k
- Forks
- 614
- Ø Merge
- 5 T. 12 Std.
- Gemergte PRs (30 T.)
- 1
Beschreibung
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,
}
}
```
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.