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.
This commit is contained in:
cpw 2018-02-26 22:49:56 -05:00 committed by LexManos
parent e299489493
commit 18144b7a0a
1 changed files with 14 additions and 9 deletions

View File

@ -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)