-
-
Notifications
You must be signed in to change notification settings - Fork 185
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
base: 1.21.1
Are you sure you want to change the base?
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.
@@ -33,9 +38,15 @@ public final class IOUtilities { | |||
StandardOpenOption.WRITE, | |||
StandardOpenOption.TRUNCATE_EXISTING | |||
}; | |||
private static final ThreadFactory THREAD_FACTORY = new NamedThreadFactory("Neoforge-IOUtilities"); |
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.
Does this factory set tbe correct context ClassLoader?
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.
For what reason is that necessary? The docs for getContextClassloader
says
If not set, the default is to inherit the context class loader from the parent thread.
Co-authored-by: Bruno Ploumhans <[email protected]>
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.