From 18144b7a0a593e46bd170815ff7351ed84ecdcbc Mon Sep 17 00:00:00 2001 From: cpw Date: Mon, 26 Feb 2018 22:49:56 -0500 Subject: [PATCH] Fix the ForgeChunkManager to use the writebehind FileIO thread for writing (#4777) the chunk file. Closes #4775 This is a performance tweak - doing File IO on the server thread during world saves causes significant lag spikes. This is one of many. --- .../common/ForgeChunkManager.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/minecraftforge/common/ForgeChunkManager.java b/src/main/java/net/minecraftforge/common/ForgeChunkManager.java index d87e7057d..9878e704c 100644 --- a/src/main/java/net/minecraftforge/common/ForgeChunkManager.java +++ b/src/main/java/net/minecraftforge/common/ForgeChunkManager.java @@ -44,6 +44,7 @@ import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.storage.AnvilChunkLoader; +import net.minecraft.world.storage.ThreadedFileIOBase; import net.minecraftforge.common.config.ConfigCategory; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; @@ -944,15 +945,19 @@ public class ForgeChunkManager } } } - try - { - CompressedStreamTools.write(forcedChunkData, chunkLoaderData); - } - catch (IOException e) - { - FMLLog.log.warn("Unable to write forced chunk data to {} - chunkloading won't work", chunkLoaderData.getAbsolutePath(), e); - return; - } + + // Write the actual file on the IO thread rather than blocking the server thread + ThreadedFileIOBase.getThreadedIOInstance().queueIO(() -> { + try + { + CompressedStreamTools.write(forcedChunkData, chunkLoaderData); + } + catch (IOException e) + { + FMLLog.log.warn("Unable to write forced chunk data to {} - chunkloading won't work", chunkLoaderData.getAbsolutePath(), e); + } + return false; + }); } static void loadEntity(Entity entity)