Merge remote-tracking branch 'origin/main' into 1.18

This commit is contained in:
embeddedt 2023-04-24 11:12:45 -04:00
commit 1248a8edf6
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
8 changed files with 92 additions and 6 deletions

View File

@ -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;
@ -23,6 +24,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;
@ -31,9 +33,8 @@ import org.embeddedt.modernfix.util.ClassInfoManager;
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
@ -52,6 +53,26 @@ public class ModernFix {
public static CountDownLatch worldLoadSemaphore = null;
private static ExecutorService resourceReloadService = null;
static {
try {
if(ModernFixMixinPlugin.instance.isOptionEnabled("perf.dedicated_reload_executor.ReloadExecutor")) {
Method makeExecutorMethod = ObfuscationReflectionHelper.findMethod(Util.class, "m_137477_", String.class);
resourceReloadService = (ExecutorService)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 ExecutorService resourceReloadExecutor() {
return resourceReloadService;
}
/**
* Simple mechanism used to delay some background processes until the client is actually in-game, to reduce
* launch time.

View File

@ -42,7 +42,6 @@ public class ModernFixMixinPlugin implements IMixinConfigPlugin {
config.getOptionCount(), config.getOptionOverrideCount());
FastAccessTransformerList.attemptReplace();
ModWorkManagerQueue.replace();
DFUBlaster.blastMaps();
/* https://github.com/FabricMC/Mixin/pull/99 */

View File

@ -34,6 +34,7 @@ public class ModernFixEarlyConfig {
this.addMixinRule("perf.reduce_blockstate_cache_rebuilds", 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);
@ -66,6 +67,7 @@ public class ModernFixEarlyConfig {
/* Mod compat */
disableIfModPresent("mixin.perf.thread_priorities", "smoothboot");
disableIfModPresent("mixin.perf.boost_worker_count", "smoothboot");
disableIfModPresent("mixin.perf.async_jei", "modernui");
disableIfModPresent("mixin.perf.compress_biome_container", "chocolate", "betterendforge");
disableIfModPresent("mixin.bugfix.mc218112", "performant");

View File

@ -0,0 +1,26 @@
package org.embeddedt.modernfix.mixin.core;
import net.minecraft.server.Bootstrap;
import org.embeddedt.modernfix.load.ModWorkManagerQueue;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Bootstrap.class)
public class BootstrapMixin {
@Shadow private static boolean isBootstrapped;
@Shadow @Final private static Logger LOGGER;
@Inject(method = "bootStrap", at = @At("HEAD"))
private static void doModernFixBootstrap(CallbackInfo ci) {
if(!isBootstrapped) {
LOGGER.info("ModernFix bootstrap");
ModWorkManagerQueue.replace();
}
}
}

View File

@ -0,0 +1,18 @@
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;
import java.util.concurrent.ExecutorService;
@Mixin(Minecraft.class)
public class MinecraftMixin {
@Redirect(method = { "<init>", "makeWorldStem(Lnet/minecraft/server/packs/repository/PackRepository;ZLnet/minecraft/server/WorldStem$DataPackConfigSupplier;Lnet/minecraft/server/WorldStem$WorldDataSupplier;)Lnet/minecraft/server/WorldStem;", "reloadResourcePacks" }, at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;backgroundExecutor()Ljava/util/concurrent/ExecutorService;", ordinal = 0))
private ExecutorService getResourceReloadExecutor() {
return ModernFix.resourceReloadExecutor();
}
}

View File

@ -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/ReloadableServerResources;loadResources(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/core/RegistryAccess$Frozen;Lnet/minecraft/commands/Commands$CommandSelection;ILjava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"), index = 4)
private Executor getReloadExecutor(Executor asyncExecutor) {
return ModernFix.resourceReloadExecutor();
}
}

View File

@ -206,7 +206,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();
@ -277,7 +277,7 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
ModernFix.LOGGER.error("Error reading model {}: {}", fileLocation, e);
return Pair.of(fileLocation, null);
}
}, Util.backgroundExecutor()));
}, ModernFix.resourceReloadExecutor()));
}
modelFiles.clear();
CompletableFuture.allOf(modelBytes.toArray(new CompletableFuture[0])).join();

View File

@ -6,11 +6,13 @@
"compatibilityLevel": "JAVA_17",
"refmap": "modernfix.refmap.json",
"mixins": [
"core.BootstrapMixin",
"bugfix.edge_chunk_not_saved.ChunkManagerMixin",
"perf.modern_resourcepacks.PathResourcePackMixin",
"perf.modern_resourcepacks.VanillaPackResourcesMixin",
"perf.dynamic_structure_manager.StructureManagerMixin",
"bugfix.chunk_deadlock.ServerChunkCacheMixin",
"perf.dedicated_reload_executor.MinecraftServerMixin",
"perf.remove_biome_temperature_cache.BiomeMixin",
"perf.reduce_blockstate_cache_rebuilds.GameDataMixin",
"perf.reduce_blockstate_cache_rebuilds.BlockCallbacksMixin",
@ -44,6 +46,7 @@
"feature.measure_time.MinecraftMixin",
"feature.reduce_loading_screen_freezes.ModelBakeryMixin",
"bugfix.concurrency.MinecraftMixin",
"perf.dedicated_reload_executor.MinecraftMixin",
"perf.dynamic_resources.BlockElementFaceDeserializerMixin",
"perf.dynamic_resources.BlockModelShaperMixin",
"perf.dynamic_resources.ItemModelShaperMixin",