From 72def15ac6dfc2f52811bfc2eb459e80ff2ab8f9 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sun, 29 Jan 2023 22:00:00 -0500 Subject: [PATCH] More tweaks to executor --- .../SyncExecutorMixin.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/embeddedt/modernfix/mixin/perf/sync_executor_sleep/SyncExecutorMixin.java b/src/main/java/org/embeddedt/modernfix/mixin/perf/sync_executor_sleep/SyncExecutorMixin.java index 5a980e59..81d59b09 100644 --- a/src/main/java/org/embeddedt/modernfix/mixin/perf/sync_executor_sleep/SyncExecutorMixin.java +++ b/src/main/java/org/embeddedt/modernfix/mixin/perf/sync_executor_sleep/SyncExecutorMixin.java @@ -13,25 +13,26 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.LockSupport; @Mixin(targets = "net/minecraftforge/fml/ModWorkManager$SyncExecutor") -public class SyncExecutorMixin { - @Shadow(remap = false) private ConcurrentLinkedDeque tasks; +public abstract class SyncExecutorMixin { + @Shadow(remap = false) public abstract boolean driveOne(); + private static final long PARK_TIME = TimeUnit.MILLISECONDS.toNanos(50); + /** * Currently FML spins in driveOne while waiting for the modloading workers. We can improve this * by sleeping for 50ms at a time. * - * Also, render FML splash screen unless there was a new task, rather than only when there was a new task + * Also, render FML splash screen regardless of task availability. * @author embeddedt * @reason improve CPU efficiency */ - @Overwrite(remap = false) - public boolean driveOne() { - final Runnable task = tasks.pollFirst(); - if (task != null) { - task.run(); - } else { + public void drive(Runnable ticker) { + int executions = 0; + do { + executions++; + ticker.run(); + } while(driveOne()); + if(executions < 2) LockSupport.parkNanos(PARK_TIME); - } - return task == null; } }