More tweaks to executor

This commit is contained in:
embeddedt 2023-01-29 22:00:00 -05:00
parent a71a036ae8
commit 72def15ac6
No known key found for this signature in database
GPG Key ID: A69433EC199B5613

View File

@ -13,25 +13,26 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport; import java.util.concurrent.locks.LockSupport;
@Mixin(targets = "net/minecraftforge/fml/ModWorkManager$SyncExecutor") @Mixin(targets = "net/minecraftforge/fml/ModWorkManager$SyncExecutor")
public class SyncExecutorMixin { public abstract class SyncExecutorMixin {
@Shadow(remap = false) private ConcurrentLinkedDeque<Runnable> tasks; @Shadow(remap = false) public abstract boolean driveOne();
private static final long PARK_TIME = TimeUnit.MILLISECONDS.toNanos(50); 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 * Currently FML spins in driveOne while waiting for the modloading workers. We can improve this
* by sleeping for 50ms at a time. * by sleeping for 50ms at a time.
* *
* Also, render FML splash screen <i>unless</i> 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 * @author embeddedt
* @reason improve CPU efficiency * @reason improve CPU efficiency
*/ */
@Overwrite(remap = false) public void drive(Runnable ticker) {
public boolean driveOne() { int executions = 0;
final Runnable task = tasks.pollFirst(); do {
if (task != null) { executions++;
task.run(); ticker.run();
} else { } while(driveOne());
if(executions < 2)
LockSupport.parkNanos(PARK_TIME); LockSupport.parkNanos(PARK_TIME);
}
return task == null;
} }
} }