Skip to content
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

Open
wants to merge 3 commits into
base: 1.21.1
Choose a base branch
from

Conversation

thiakil
Copy link
Contributor

@thiakil thiakil commented Dec 24, 2024

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.

@neoforged-automation neoforged-automation bot added the 1.21.1 Targeted at Minecraft 1.21.1 label Dec 24, 2024
@neoforged-pr-publishing
Copy link

  • Publish PR to GitHub Packages

@Technici4n
Copy link
Member

Does vanilla not perform this IO on the main thread already?

@Technici4n
Copy link
Member

We need to be a bit careful I think:

  • Moving IO to a separate thread just to block until completion will not improve global performance unless IO is performed in parallel.
  • It looks like the bottleneck is the actual disk write. Doing that in parallel or on a different thread shouldn't bring improvements?

@thiakil
Copy link
Contributor Author

thiakil commented Dec 24, 2024

Does vanilla not perform this IO on the main thread already?

Yes, but it does not force a flush to disk and an atomic move. Plus scaling.

to block until completion

Not quite what's happening. That's only when /save-all flush is used. Normally the io will complete in the background, which is why only one thread

marchermans
marchermans previously approved these changes Dec 24, 2024
Copy link
Contributor

@marchermans marchermans left a 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.

Copy link
Member

@Technici4n Technici4n left a 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");
Copy link
Member

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?

Copy link
Contributor Author

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.21.1 Targeted at Minecraft 1.21.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants