fix: move async save commit off game thread to prevent disk I/O stall

StorageManager.SaveSaveData() blocks until the disk write completes.
Calling it from the game thread caused 2.5s freezes. Now it only runs
from TickCoreSystems() on the ServerMain thread, which operates
independently of the game tick loop.
This commit is contained in:
itsRevela 2026-04-01 01:49:58 -05:00
parent 68521f8c92
commit 9372b2d2ea
2 changed files with 1 additions and 6 deletions

View file

@ -2258,11 +2258,6 @@ void MinecraftServer::tick()
PIXBeginNamedEvent(0,"Players tick");
players->tick();
PIXEndNamedEvent();
#if defined(_WINDOWS64)
// Commit any pending async autosave on the game thread (same thread
// that called Flush/AllocateSaveData, which StorageManager requires).
ConsoleSaveFileOriginal::CommitPendingAsyncSave();
#endif
PIXBeginNamedEvent(0,"Connection tick");
connection->tick();
PIXEndNamedEvent();

View file

@ -19,7 +19,7 @@ This project is based on source code of Minecraft Legacy Console Edition v1.6.05
- Autosave no longer freezes the server. Previously, every autosave compressed the entire world save file with zlib synchronously on the main thread, blocking all game ticks for 2-6 seconds depending on world size
- The save buffer is now snapshotted (memcpy) while holding the save lock (~18ms), then compression runs on a detached background thread. Once compression finishes, the compressed data is committed back to StorageManager on the next game tick. If a previous async save is still in flight, it falls back to the original synchronous path to prevent unbounded queuing
- Autosave on the dedicated server now only flushes entity data instead of re-saving all dirty chunks, matching the Xbox/Orbis behavior. Chunks are already saved continuously by the per-tick trickle save process
- The async save commit runs from both the game thread tick and the ServerMain tick loop (via `TickCoreSystems`), ensuring saves complete during bootstrap, normal gameplay, and shutdown
- The async save commit (`StorageManager.SaveSaveData`) runs exclusively on the ServerMain thread (via `TickCoreSystems`), keeping the blocking disk write off the game thread entirely
- Autosave timing breakdown is now logged to `server.log` for diagnostics (e.g. `autosave breakdown: players=0ms levels=0ms rules=0ms flush=18ms total=18ms`)
### Dedicated Server Entity Tracking Optimization