-
-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
move SavedData.save to IO worker to avoid synchronous IO on main thread #1796
move SavedData.save to IO worker to avoid synchronous IO on main thread #1796
Conversation
|
Does vanilla not perform this IO on the main thread already? |
We need to be a bit careful I think:
|
Yes, but it does not force a flush to disk and an atomic move. Plus scaling.
Not quite what's happening. That's only when |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @Technici4n That we need to be majorly carefull here.
We introduced the default always flush/atomic-move behaviour to make sure that capabilities and modded savedata are always written.
This change in and of itself seems to be fine, but future changes might re-open that can of worms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanations. Moving IO off-thread is quite nice since we are already doing atomic moves that should be safe to perform concurrently.
Co-authored-by: Bruno Ploumhans <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally managed to take a closer look at this. The proposed solution is fine and my initial worries turned out to be completely unjustified. However, I would like to simplify the implementation by making it closer to what Mojang did in 1.21.4: Instead of spinning up a custom executor, manually adding the tasks and then shutting it down to wait on the remaining tasks in case of a flush, the individual IO tasks can be chained with CompletableFuture#thenRunAsync()
using the Util.ioPool()
executor (non-daemon, so it's safe to use for critical stuff like this and it's what vanilla uses in 1.21.4), storing the latest future in a field and then joining on it when necessary. If desired, the last future can also be cleared after then join by setting the field to CompletableFuture.completedFuture(null)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
🚀 This PR has been released as NeoForge version |
The new Atomic Move changes to
SavedData
are causing synchronous IO on the main/server thread, even when saving should be asynchronous.This is adds up in large modpacks
Ref 1 2
This PR moves that to an IO worker and adds waiting in the appropriate places.