perf: async autosave for dedicated server

Autosave previously froze the main thread for 2-6 seconds while
compressing the entire save file with zlib. Now the save buffer is
snapshotted under the lock (~18ms), then compression runs on a
background thread. The compressed data is committed to StorageManager
on the next main-thread tick via CommitPendingAsyncSave().

Also skip redundant full chunk saves during autosave on the dedicated
server -- chunks are already persisted by the per-tick trickle save.
Only entity data is flushed, matching Xbox/Orbis behavior.

Added per-step timing to the autosave handler for diagnostics.
This commit is contained in:
itsRevela
2026-03-31 23:33:21 -05:00
parent 450891d8c4
commit 073a511217
6 changed files with 227 additions and 2 deletions

View File

@@ -977,8 +977,11 @@ void ServerLevel::save(bool force, ProgressListener *progressListener, bool bAut
if (progressListener != nullptr) progressListener->progressStage(IDS_PROGRESS_SAVING_CHUNKS);
#if defined(_XBOX_ONE) || defined(__ORBIS__)
// Our autosave is a minimal save. All the chunks are saves by the constant save process
#if defined(_XBOX_ONE) || defined(__ORBIS__) || (defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD))
// Autosave is a minimal save. Chunks are saved continuously by the
// per-tick trickle save process (ServerChunkCache::tick), so we only
// need to flush entity data here. The full chunkSource->save() would
// redundantly re-save all dirty chunks and block the main thread.
if(bAutosave)
{
chunkSource->saveAllEntities();