Move resource reloading to dedicated executor
Allows benefiting from Smooth Boot in-game (as intended) while not slowing down launch
This commit is contained in:
parent
66d1faa7e3
commit
86629e7773
|
|
@ -1,6 +1,7 @@
|
|||
package org.embeddedt.modernfix;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.server.level.ChunkHolder;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
|
@ -24,6 +25,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.embeddedt.modernfix.classloading.ModFileScanDataDeduplicator;
|
||||
import org.embeddedt.modernfix.core.ModernFixMixinPlugin;
|
||||
import org.embeddedt.modernfix.core.config.ModernFixConfig;
|
||||
import org.embeddedt.modernfix.entity.EntityDataIDSyncHandler;
|
||||
import org.embeddedt.modernfix.packet.PacketHandler;
|
||||
|
|
@ -34,9 +36,8 @@ import org.embeddedt.modernfix.util.KubeUtil;
|
|||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
// The value here should match an entry in the META-INF/mods.toml file
|
||||
|
|
@ -55,6 +56,26 @@ public class ModernFix {
|
|||
|
||||
public static CountDownLatch worldLoadSemaphore = null;
|
||||
|
||||
private static Executor resourceReloadService = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
if(ModernFixMixinPlugin.instance.isOptionEnabled("perf.dedicated_reload_executor.ReloadExecutor")) {
|
||||
Method makeExecutorMethod = ObfuscationReflectionHelper.findMethod(Util.class, "func_240979_a_", String.class);
|
||||
resourceReloadService = (Executor)makeExecutorMethod.invoke(null, "ResourceReload");
|
||||
} else {
|
||||
resourceReloadService = Util.backgroundExecutor();
|
||||
}
|
||||
} catch(RuntimeException | ReflectiveOperationException e) {
|
||||
LOGGER.error("Could not create resource reload executor", e);
|
||||
resourceReloadService = Util.backgroundExecutor();
|
||||
}
|
||||
}
|
||||
|
||||
public static Executor resourceReloadExecutor() {
|
||||
return resourceReloadService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple mechanism used to delay some background processes until the client is actually in-game, to reduce
|
||||
* launch time.
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ public class ModernFixEarlyConfig {
|
|||
this.addMixinRule("perf.reuse_datapacks", true);
|
||||
this.addMixinRule("perf.model_optimizations", true);
|
||||
this.addMixinRule("perf.dynamic_resources", false);
|
||||
this.addMixinRule("perf.dedicated_reload_executor", true);
|
||||
/* Use a simpler ArrayMap if FerriteCore is using the map intelligently anyway */
|
||||
this.addMixinRule("perf.state_definition_construct", modPresent("ferritecore"));
|
||||
this.addMixinRule("perf.cache_strongholds", true);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package org.embeddedt.modernfix.mixin.perf.dedicated_reload_executor;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.embeddedt.modernfix.ModernFix;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public class MinecraftMixin {
|
||||
@Redirect(method = { "<init>", "makeServerStem", "reloadResourcePacks" }, at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;backgroundExecutor()Ljava/util/concurrent/Executor;", ordinal = 0))
|
||||
private Executor getResourceReloadExecutor() {
|
||||
return ModernFix.resourceReloadExecutor();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package org.embeddedt.modernfix.mixin.perf.dedicated_reload_executor;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.embeddedt.modernfix.ModernFix;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class MinecraftServerMixin {
|
||||
@ModifyArg(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/ServerResources;loadResources(Ljava/util/List;Lnet/minecraft/commands/Commands$CommandSelection;ILjava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"), index = 3)
|
||||
private Executor getReloadExecutor(Executor asyncExecutor) {
|
||||
return ModernFix.resourceReloadExecutor();
|
||||
}
|
||||
}
|
||||
|
|
@ -208,7 +208,7 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
|
|||
ModernFix.LOGGER.error("Error reading blockstate {}: {}", blockstate, e);
|
||||
}
|
||||
return Pair.of(blockstate, null);
|
||||
}, Util.backgroundExecutor()));
|
||||
}, ModernFix.resourceReloadExecutor()));
|
||||
}
|
||||
blockStateFiles = null;
|
||||
CompletableFuture.allOf(blockStateData.toArray(new CompletableFuture[0])).join();
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
"bugfix.refinedstorage.te_bug.ItemExternalStorageMixin",
|
||||
"bugfix.chunk_deadlock.ServerChunkCacheMixin",
|
||||
"bugfix.chunk_deadlock.valhesia.BlockStateBaseMixin",
|
||||
"perf.dedicated_reload_executor.MinecraftServerMixin",
|
||||
"perf.remove_biome_temperature_cache.BiomeMixin",
|
||||
"perf.resourcepacks.ModFileResourcePackMixin",
|
||||
"perf.resourcepacks.VanillaPackMixin",
|
||||
|
|
@ -79,6 +80,7 @@
|
|||
"bugfix.concurrency.RenderTypeMixin",
|
||||
"bugfix.concurrency.MinecraftMixin",
|
||||
"bugfix.concurrency.StaticTagHelperMixin",
|
||||
"perf.dedicated_reload_executor.MinecraftMixin",
|
||||
"perf.dynamic_resources.BlockElementFaceDeserializerMixin",
|
||||
"perf.dynamic_resources.BlockModelShaperMixin",
|
||||
"perf.dynamic_resources.ItemModelShaperMixin",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user