Skip to content

Commit 9e3e732

Browse files
committed
Fix MC-183518
1 parent 226e4a3 commit 9e3e732

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.embeddedt.modernfix.common.mixin.perf.fix_loop_spin_waiting;
2+
3+
import net.minecraft.util.thread.BlockableEventLoop;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.injection.At;
6+
import org.spongepowered.asm.mixin.injection.ModifyArg;
7+
import org.spongepowered.asm.mixin.injection.Redirect;
8+
9+
import java.util.concurrent.TimeUnit;
10+
11+
// This should fix https://bugs.mojang.com/browse/MC-183518
12+
@Mixin(BlockableEventLoop.class)
13+
public class BlockableEventLoopMixin {
14+
/**
15+
* @author embeddedt
16+
* @reason yielding the thread is pretty pointless if we're about to park anyway
17+
*/
18+
@Redirect(method = "waitForTasks", at = @At(value = "INVOKE", target = "Ljava/lang/Thread;yield()V"), require = 0)
19+
private void doNotYield() {}
20+
21+
private static final long MFIX$TICK_WAIT_TIME = TimeUnit.MILLISECONDS.toNanos(2);
22+
23+
/**
24+
* @author embeddedt
25+
* @reason park for more than 0.1ms at a time. Task submission will call unpark(), so the thread will become
26+
* runnable again if a task is submitted.
27+
*/
28+
@ModifyArg(method = "waitForTasks", at = @At(value = "INVOKE", target = "Ljava/util/concurrent/locks/LockSupport;parkNanos(Ljava/lang/Object;J)V"), index = 1, require = 0)
29+
private long changeParkDuration(long originalDuration) {
30+
return MFIX$TICK_WAIT_TIME;
31+
}
32+
}

0 commit comments

Comments
 (0)