-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to ConcurrentUtil 0.0.2, and refactor I/O + worker pool
With ConcurrentUtil 0.0.2, we can make all thread pools (worker+I/O) have their thread counts configurable on the fly. The new I/O system splits the compression/decompression work from the I/O. The compression/decompression is ran on the worker pool, while the I/O is ran on the I/O pool. This allows for better cpu utilisation control on systems with low core counts, and allows higher read/write speeds on systems with higher core counts. Additionally, the I/O scheduling for thread counts > 1 is also improved as it longer selects a thread to schedule based on the chunk location.
- Loading branch information
1 parent
6a2c6d2
commit bfaddd3
Showing
42 changed files
with
1,728 additions
and
915 deletions.
There are no files selected for viewing
Submodule ConcurrentUtil
updated
from e49c7f to 7733f5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/ca/spottedleaf/moonrise/common/config/PostDeserializeHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ca.spottedleaf.moonrise.common.config; | ||
|
||
public interface PostDeserializeHook { | ||
|
||
public void deserialize(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/ca/spottedleaf/moonrise/common/misc/LazyRunnable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package ca.spottedleaf.moonrise.common.misc; | ||
|
||
import ca.spottedleaf.concurrentutil.util.ConcurrentUtil; | ||
import java.lang.invoke.VarHandle; | ||
|
||
public final class LazyRunnable implements Runnable { | ||
|
||
private volatile Runnable toRun; | ||
private static final VarHandle TO_RUN_HANDLE = ConcurrentUtil.getVarHandle(LazyRunnable.class, "toRun", Runnable.class); | ||
|
||
public void setRunnable(final Runnable run) { | ||
final Runnable prev = (Runnable)TO_RUN_HANDLE.compareAndExchange(this, (Runnable)null, run); | ||
if (prev != null) { | ||
throw new IllegalStateException("Runnable already set"); | ||
} | ||
} | ||
|
||
@Override | ||
public void run() { | ||
((Runnable)TO_RUN_HANDLE.getVolatile(this)).run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ChunkBufferMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package ca.spottedleaf.moonrise.mixin.chunk_system; | ||
|
||
import ca.spottedleaf.moonrise.patches.chunk_system.storage.ChunkSystemChunkBuffer; | ||
import net.minecraft.world.level.ChunkPos; | ||
import net.minecraft.world.level.chunk.storage.RegionFile; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
|
||
@Mixin(RegionFile.ChunkBuffer.class) | ||
public abstract class ChunkBufferMixin extends ByteArrayOutputStream implements ChunkSystemChunkBuffer { | ||
|
||
@Shadow | ||
@Final | ||
private ChunkPos pos; | ||
|
||
@Unique | ||
private boolean writeOnClose = true; | ||
|
||
@Override | ||
public final boolean moonrise$getWriteOnClose() { | ||
return this.writeOnClose; | ||
} | ||
|
||
@Override | ||
public final void moonrise$setWriteOnClose(final boolean value) { | ||
this.writeOnClose = value; | ||
} | ||
|
||
@Override | ||
public final void moonrise$write(final RegionFile regionFile) throws IOException { | ||
regionFile.write(this.pos, ByteBuffer.wrap(this.buf, 0, this.count)); | ||
} | ||
|
||
/** | ||
* @reason Allow delaying write I/O until later | ||
* @author Spottedleaf | ||
*/ | ||
@Redirect( | ||
method = "close", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/level/chunk/storage/RegionFile;write(Lnet/minecraft/world/level/ChunkPos;Ljava/nio/ByteBuffer;)V" | ||
) | ||
) | ||
private void redirectClose(final RegionFile instance, final ChunkPos chunkPos, final ByteBuffer byteBuffer) throws IOException { | ||
if (this.writeOnClose) { | ||
instance.write(chunkPos, byteBuffer); | ||
} | ||
} | ||
} |
Oops, something went wrong.