Compare commits

...

3 Commits

Author SHA1 Message Date
Jason Penilla
500c0777f8 Raise priority of occlusion task
Having this at a higher priority than section render tasks seems to give better results anecdotally
2024-10-23 15:38:59 -07:00
Jason Penilla
b5b6e38cb7 attempt to execute task on #get to minimize blocking 2024-10-23 10:35:35 -07:00
Jason Penilla
e69eeba47c Use Moonrise executor for section occlusion tasks 2024-10-23 10:35:35 -07:00
3 changed files with 58 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ public final class MoonriseCommon {
public static final long WORKER_QUEUE_HOLD_TIME = (long)(20.0e6); // 20ms public static final long WORKER_QUEUE_HOLD_TIME = (long)(20.0e6); // 20ms
public static final int CLIENT_DIVISION = 0; public static final int CLIENT_DIVISION = 0;
public static final PrioritisedThreadPool.ExecutorGroup RENDER_EXECUTOR_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(CLIENT_DIVISION, 0); public static final PrioritisedThreadPool.ExecutorGroup RENDER_EXECUTOR_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(CLIENT_DIVISION, 0);
public static final PrioritisedThreadPool.ExecutorGroup SECTION_OCCLUSION_EXECUTOR_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(CLIENT_DIVISION, 0);
public static final int SERVER_DIVISION = 1; public static final int SERVER_DIVISION = 1;
public static final PrioritisedThreadPool.ExecutorGroup PARALLEL_GEN_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(SERVER_DIVISION, 0); public static final PrioritisedThreadPool.ExecutorGroup PARALLEL_GEN_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(SERVER_DIVISION, 0);
public static final PrioritisedThreadPool.ExecutorGroup RADIUS_AWARE_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(SERVER_DIVISION, 0); public static final PrioritisedThreadPool.ExecutorGroup RADIUS_AWARE_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(SERVER_DIVISION, 0);

View File

@@ -0,0 +1,56 @@
package ca.spottedleaf.moonrise.mixin.render;
import ca.spottedleaf.concurrentutil.executor.PrioritisedExecutor;
import ca.spottedleaf.concurrentutil.executor.thread.PrioritisedThreadPool;
import ca.spottedleaf.concurrentutil.util.Priority;
import ca.spottedleaf.moonrise.common.util.MoonriseCommon;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import net.minecraft.client.renderer.SectionOcclusionGraph;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(SectionOcclusionGraph.class)
abstract class SectionOcclusionGraphMixin {
@Unique
private static final PrioritisedThreadPool.ExecutorGroup.ThreadPoolExecutor SECTION_OCCLUSION_EXECUTOR = MoonriseCommon.SECTION_OCCLUSION_EXECUTOR_GROUP.createExecutor(
-1, MoonriseCommon.WORKER_QUEUE_HOLD_TIME, 0
);
/**
* @reason Change executor to use our thread pool
* Note: even at normal priority, our worker pool will try to share resources equally rather than having it
* be a free-for-all
* @author jpenilla
*/
@Redirect(
method = "scheduleFullUpdate",
at = @At(
value = "INVOKE",
target = "Ljava/util/concurrent/CompletableFuture;runAsync(Ljava/lang/Runnable;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"
)
)
private CompletableFuture<Void> changeExecutor(final Runnable runnable, final Executor executor) {
final PrioritisedExecutor.PrioritisedTask[] prioritisedTask = new PrioritisedExecutor.PrioritisedTask[1];
final CompletableFuture<Void> future = new CompletableFuture<>() {
@Override
public Void get() throws InterruptedException, ExecutionException {
prioritisedTask[0].execute();
return super.get();
}
};
prioritisedTask[0] = SECTION_OCCLUSION_EXECUTOR.queueTask(() -> {
try {
runnable.run();
future.complete(null);
} catch (final Throwable throwable) {
future.completeExceptionally(throwable);
}
}, Priority.HIGH); // Higher than SectionRenderDispatcherMixin#changeExecutor
return future;
}
}

View File

@@ -128,6 +128,7 @@
"config.MinecraftMixin", "config.MinecraftMixin",
"loading_screen.LevelLoadStatusManagerMixin", "loading_screen.LevelLoadStatusManagerMixin",
"profiler.MinecraftMixin", "profiler.MinecraftMixin",
"render.SectionOcclusionGraphMixin",
"render.SectionRenderDispatcherMixin", "render.SectionRenderDispatcherMixin",
"serverlist.ClientConnectionMixin", "serverlist.ClientConnectionMixin",
"serverlist.ServerAddressResolverMixin", "serverlist.ServerAddressResolverMixin",