Minor optimization to ForgeRegistry.validateContent

This commit is contained in:
embeddedt 2023-02-24 13:17:44 -05:00
parent 7868bd90ee
commit 7f018c1ff7
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
3 changed files with 31 additions and 1 deletions

View File

@ -19,6 +19,7 @@ public class ModernFixEarlyConfig {
this.addMixinRule("core", true); // TODO: Don't actually allow the user to disable this
this.addMixinRule("feature.measure_time", true);
this.addMixinRule("feature.reduce_loading_screen_freezes", false);
this.addMixinRule("perf.fast_registry_validation", true);
this.addMixinRule("perf.remove_biome_temperature_cache", true);
this.addMixinRule("perf.resourcepacks", true);
this.addMixinRule("perf.reduce_blockstate_cache_rebuilds", true);

View File

@ -0,0 +1,28 @@
package org.embeddedt.modernfix.mixin.perf.fast_registry_validation;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.minecraftforge.registries.ForgeRegistry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.lang.reflect.Method;
@Mixin(value = ForgeRegistry.class, remap = false)
public class ForgeRegistryMixin {
private static Method bitSetTrimMethod = null;
private static boolean bitSetTrimMethodRetrieved = false;
/**
* Cache the result of findMethod instead of running it multiple times.
* Null checks are not required as the surrounding code handles it already.
*/
@Redirect(method = "validateContent", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/ObfuscationReflectionHelper;findMethod(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"))
private Method skipMultipleRemap(Class<?> clz, String methodName, Class<?>[] params) {
if(!bitSetTrimMethodRetrieved) {
bitSetTrimMethodRetrieved = true;
bitSetTrimMethod = ObfuscationReflectionHelper.findMethod(clz, methodName, params);
}
return bitSetTrimMethod;
}
}

View File

@ -47,7 +47,8 @@
"perf.kubejs.RecipeEventJSMixin",
"perf.kubejs.RecipeJSMixin",
"perf.kubejs.IDFilterMixin",
"perf.kubejs.CustomIngredientMixin"
"perf.kubejs.CustomIngredientMixin",
"perf.fast_registry_validation.ForgeRegistryMixin"
],
"client": [
"core.MinecraftMixin",