Adjust thread priorities
This commit is contained in:
parent
edc7ed470c
commit
87b644834f
|
|
@ -22,16 +22,20 @@ public class ModernFixConfig {
|
|||
|
||||
public static ForgeConfigSpec.ConfigValue<List<? extends String>> BLACKLIST_ASYNC_JEI_PLUGINS;
|
||||
|
||||
public static ForgeConfigSpec.IntValue INTEGRATED_SERVER_PRIORITY;
|
||||
public static ForgeConfigSpec.IntValue BACKGROUND_WORKER_PRIORITY;
|
||||
|
||||
public static Set<ResourceLocation> jeiPluginBlacklist;
|
||||
|
||||
static {
|
||||
List<? extends String> empty = Collections.emptyList();
|
||||
Predicate<Object> locationValidator = o -> o instanceof String && ((String)o).contains(":");
|
||||
BLACKLIST_ASYNC_JEI_PLUGINS = COMMON_BUILDER
|
||||
.comment("These JEI plugins will be loaded on the main thread")
|
||||
.defineList("blacklist_async_jei_plugins", ImmutableList.of(
|
||||
"jepb:jei_plugin"
|
||||
), locationValidator);
|
||||
INTEGRATED_SERVER_PRIORITY = COMMON_BUILDER.comment("Thread priority to use for the integrated server. By default this is one less than the client thread, to help prevent the server from lowering FPS.").defineInRange("integratedServerPriority", 4, 1, 10);
|
||||
BACKGROUND_WORKER_PRIORITY = COMMON_BUILDER.comment("Priority to use for the background workers that complete various tasks. By default this is one less than the client thread.").defineInRange("backgroundWorkerPriority", 4, 1, 10);
|
||||
}
|
||||
|
||||
static {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.embeddedt.modernfix.core.config;
|
||||
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
|
@ -27,6 +28,12 @@ public class ModernFixEarlyConfig {
|
|||
this.addMixinRule("bugfix.concurrency", true);
|
||||
this.addMixinRule("bugfix.edge_chunk_not_saved", true);
|
||||
this.addMixinRule("perf.async_jei", true);
|
||||
this.addMixinRule("perf.thread_priorities", true);
|
||||
|
||||
/* Mod compat */
|
||||
if(FMLLoader.getLoadingModList().getModFileById("smoothboot") != null) {
|
||||
this.options.get("mixin.perf.thread_priorities").addModOverride(false, "smoothboot");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
package org.embeddedt.modernfix.mixin.perf.thread_priorities;
|
||||
|
||||
import com.mojang.authlib.GameProfileRepository;
|
||||
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.resources.DataPackRegistries;
|
||||
import net.minecraft.resources.ResourcePackList;
|
||||
import net.minecraft.server.integrated.IntegratedServer;
|
||||
import net.minecraft.server.management.PlayerProfileCache;
|
||||
import net.minecraft.util.registry.DynamicRegistries;
|
||||
import net.minecraft.world.chunk.listener.IChunkStatusListenerFactory;
|
||||
import net.minecraft.world.storage.IServerConfiguration;
|
||||
import net.minecraft.world.storage.SaveFormat;
|
||||
import org.embeddedt.modernfix.ModernFix;
|
||||
import org.embeddedt.modernfix.core.config.ModernFixConfig;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(IntegratedServer.class)
|
||||
public class IntegratedServerMixin {
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
private void adjustServerPriority(Thread pServerThread, Minecraft pMinecraft, DynamicRegistries.Impl pRegistryHolder, SaveFormat.LevelSave pStorageSource, ResourcePackList pPackRepository, DataPackRegistries pResources, IServerConfiguration pWorldData, MinecraftSessionService pSessionService, GameProfileRepository pProfileRepository, PlayerProfileCache pProfileCache, IChunkStatusListenerFactory pProgressListenerfactory, CallbackInfo ci) {
|
||||
int pri = ModernFixConfig.INTEGRATED_SERVER_PRIORITY.get();
|
||||
ModernFix.LOGGER.info("Changing server thread priority to " + pri);
|
||||
pServerThread.setPriority(pri);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package org.embeddedt.modernfix.mixin.perf.thread_priorities;
|
||||
|
||||
import net.minecraft.util.Util;
|
||||
import org.embeddedt.modernfix.ModernFix;
|
||||
import org.embeddedt.modernfix.core.config.ModernFixConfig;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.ForkJoinWorkerThread;
|
||||
|
||||
@Mixin(Util.class)
|
||||
public class UtilMixin {
|
||||
@ModifyArg(method = "makeExecutor", at = @At(value = "INVOKE", target = "Ljava/util/concurrent/ForkJoinPool;<init>(ILjava/util/concurrent/ForkJoinPool$ForkJoinWorkerThreadFactory;Ljava/lang/Thread$UncaughtExceptionHandler;Z)V"), index = 1)
|
||||
private static ForkJoinPool.ForkJoinWorkerThreadFactory adjustPriorityOfThreadFactory(ForkJoinPool.ForkJoinWorkerThreadFactory factory) {
|
||||
return pool -> {
|
||||
ForkJoinWorkerThread thread = factory.newThread(pool);
|
||||
int pri = ModernFixConfig.BACKGROUND_WORKER_PRIORITY.get();
|
||||
ModernFix.LOGGER.info("Changing priority of " + thread.getName() + " to " + pri);
|
||||
thread.setPriority(pri);
|
||||
return thread;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,8 @@
|
|||
"perf.reduce_blockstate_cache_rebuilds.AbstractBlockStateMixin",
|
||||
"perf.reduce_blockstate_cache_rebuilds.GameDataMixin",
|
||||
"perf.reduce_blockstate_cache_rebuilds.BlockCallbacksMixin",
|
||||
"perf.boost_worker_count.UtilMixin"
|
||||
"perf.boost_worker_count.UtilMixin",
|
||||
"perf.thread_priorities.UtilMixin"
|
||||
],
|
||||
"client": [
|
||||
"perf.skip_first_datapack_reload.MinecraftMixin",
|
||||
|
|
@ -29,7 +30,8 @@
|
|||
"perf.async_jei.ClientLifecycleHandlerMixin",
|
||||
"perf.async_jei.JeiStarterMixin",
|
||||
"perf.async_jei.PluginCallerMixin",
|
||||
"perf.async_jei.RecipeManagerInternalMixin"
|
||||
"perf.async_jei.RecipeManagerInternalMixin",
|
||||
"perf.thread_priorities.IntegratedServerMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user