optimization: async dedicated server autosaving#1473
Merged
sylvessa merged 1 commit intosmartcmd:mainfrom Apr 5, 2026
Merged
Conversation
mattsumi
approved these changes
Apr 5, 2026
Collaborator
Author
|
merging since mattsumi has looked through it |
itsRevela
pushed a commit
to itsRevela/MinecraftConsoles
that referenced
this pull request
Apr 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
makes autosave async on the dedicated server so it doesnt block the tick thread during compression
Changes
Previous Behavior
calling
Flush()on the server would block the entire tick thread while it compressed. No idea why this is ran on main thread especially in a server, I'm pretty suire this was changed later on. for large worlds this caused noticeable lag and made the server practically freeze during autosaves.from 1 autosave on a 350mb world ran on the dedicated server (latest nightly)
8mb.video-DBu-nhFFpcs7.mp4
Root Cause
Flush()did all compression work synchronously. the tick thread had to sit and wait for zlib to finish compressing the full save buffer before it could continue. this caused the server to freeze for a few seconds depending on the world size and hardware.New Behavior
Flush()snapshotspvSaveMeminto a heap buffer under the critical section, releases the lock immediately, then hands the snapshot off to a seperate thread that does all the compression. once the bacjground thread finishes, the result gets picked up the main thread next tick and commits it toStorageManager.also when server stops it waits until this all does its thing, i had ran into an issue where it would just do the save in a seperate thread then just stop without actually writing, so it waits until thats done
With this, theres no noticable lag when autosaving, users can still play chat etc while autosave occurs
8mb.video-yhl-N2B3epoD.mp4
3 autosaves happened in this video, on a 350mb world ran on the dedicated server with the async autosave
Fix Implementation
ConsoleSaveFileOriginal now has two new funcs, flushPendingBackgroundSave which gets called bny the tickcoresystems in servermain.cpp, and hasPendingBackgroundSave for checks by servermain.cpp before closing down the server fully
Flush()now gathers the snapshot which contains all the save data and etc, and then writes to disk etc in its own thread, Result sits untilflushPendingBackgroundSavegets picked up by the tickcoresystems and then actually commits toStorageManagerStorageManager is Unfortunately not thread safe (oops) so the actual commit has to stay on the main thread.
flush() onlt runs in a seperate thread IF set to dedicated server btw. I made sure not to touch the save stuff when ran as client lol.
AI Use Disclosure
no
Related Issues