LRU chunk eviction (bounded cache, default 1024 chunks / ~200MB)
The in-memory chunk+frame cache no longer grows unbounded as players explore. An LRU policy (doubly-linked list + index map, O(1) per op) evicts least-recently-used chunks when the cache exceeds MaxCachedChunks, dropping both the chunk and its cached frame. Dirty chunks are skipped until the autosave flushes them, so no edit is ever lost to eviction. - world/cache.go: maxChunks field + order/index LRU bookkeeping; touch (move-to-front) on every chunkAt/Frame/SetBlock hit; evictIfNeeded on miss; NewCacheWithLimit constructor (0 = unbounded, backward-compat). Dirty chunks are bumped to MRU and left in place rather than doing region I/O under the cache mutex. - server/server.go: Config.MaxCachedChunks (default 1024); New wires it into NewCacheWithLimit when a world dir is set. - cmd/regionio/main.go: -maxcache flag. - Tests: limit cap, LRU ordering (touched chunk survives), both-maps drop, dirty-keep, reload-on-access, and edits-survive-eviction+reload (end-to-end via the store).
This commit is contained in:
parent
d7c80a8858
commit
65a7445a78
4 changed files with 269 additions and 10 deletions
|
|
@ -28,10 +28,12 @@ func main() {
|
|||
seedFlag := flag.Int64("seed", parseSeedEnv(os.Getenv("REGIONIO_SEED"), cfg.WorldSeed, log),
|
||||
"world seed (overrides REGIONIO_SEED)")
|
||||
worldDir := flag.String("world", cfg.WorldDir, "world directory (empty = in-memory only)")
|
||||
maxCache := flag.Int("maxcache", cfg.MaxCachedChunks, "max cached chunks, LRU eviction (0 = unbounded)")
|
||||
flag.Parse()
|
||||
cfg.WorldSeed = *seedFlag
|
||||
cfg.WorldDir = *worldDir
|
||||
log.Info("using world seed", "seed", cfg.WorldSeed, "worldDir", cfg.WorldDir)
|
||||
cfg.MaxCachedChunks = *maxCache
|
||||
log.Info("using world seed", "seed", cfg.WorldSeed, "worldDir", cfg.WorldDir, "maxcache", cfg.MaxCachedChunks)
|
||||
|
||||
srv, err := server.New(cfg)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue