Avoid spinning in Minecraft.doWorldLoad

This commit is contained in:
embeddedt 2026-03-19 20:36:07 -04:00
parent a9340b2642
commit 18dc488ab9
No known key found for this signature in database
GPG Key ID: A69433EC199B5613

View File

@ -0,0 +1,24 @@
package org.embeddedt.modernfix.common.mixin.perf.suspend_integrated_server_during_load;
import net.minecraft.client.Minecraft;
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(Minecraft.class)
@ClientOnlyMixin
public class MinecraftMixin {
/**
* @author embeddedt
* @reason spin-waiting burns CPU time on the main thread, when the server thread is likely to take some time
* to be ready.
*/
@Redirect(method = "doWorldLoad", at = @At(value = "INVOKE", target = "Ljava/lang/Thread;yield()V"))
private void sleepInsteadOfYield() {
try {
Thread.sleep(16L);
} catch (InterruptedException ignored) {
}
}
}