From 9372b2d2eab27b3e8f97032ecd87ab58c887fc74 Mon Sep 17 00:00:00 2001 From: itsRevela Date: Wed, 1 Apr 2026 01:49:58 -0500 Subject: [PATCH] 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. --- Minecraft.Client/MinecraftServer.cpp | 5 ----- README.md | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Minecraft.Client/MinecraftServer.cpp b/Minecraft.Client/MinecraftServer.cpp index 6ddbd580..67b9b399 100644 --- a/Minecraft.Client/MinecraftServer.cpp +++ b/Minecraft.Client/MinecraftServer.cpp @@ -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(); diff --git a/README.md b/README.md index 687e2718..9c753d5a 100644 --- a/README.md +++ b/README.md @@ -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