Add experimental KubeJS memory usage optimization
This commit is contained in:
parent
0f94634361
commit
ab9880159e
|
|
@ -1,12 +1,20 @@
|
||||||
package org.embeddedt.modernfix.common.mixin.perf.kubejs;
|
package org.embeddedt.modernfix.common.mixin.perf.kubejs;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import dev.latvian.mods.kubejs.recipe.RecipeJS;
|
||||||
import dev.latvian.mods.kubejs.recipe.RecipesEventJS;
|
import dev.latvian.mods.kubejs.recipe.RecipesEventJS;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.item.crafting.Recipe;
|
||||||
|
import net.minecraft.world.item.crafting.RecipeManager;
|
||||||
import org.embeddedt.modernfix.ModernFix;
|
import org.embeddedt.modernfix.ModernFix;
|
||||||
|
import org.embeddedt.modernfix.annotation.FeatureLevel;
|
||||||
import org.embeddedt.modernfix.annotation.RequiresMod;
|
import org.embeddedt.modernfix.annotation.RequiresMod;
|
||||||
|
import org.embeddedt.modernfix.core.config.ModernFixEarlyConfig;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
@ -49,4 +57,30 @@ public class RecipeEventJSMixin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author embeddedt
|
||||||
|
* @reason once datapackRecipeMap is iterated, it is never referenced again, so clear it to avoid retaining
|
||||||
|
* references to the JSON objects
|
||||||
|
*/
|
||||||
|
@Inject(method = "post", at = @At(value = "NEW", target = "()Ljava/util/concurrent/ConcurrentLinkedQueue;", ordinal = 0), remap = false)
|
||||||
|
private void modernfix$clearDatapackRecipeMap(RecipeManager recipeManager, Map<ResourceLocation, JsonElement> datapackRecipeMap, CallbackInfo ci) {
|
||||||
|
if (ModernFixEarlyConfig.ACTIVE_FEATURE_LEVEL.isAtLeast(FeatureLevel.BETA)) {
|
||||||
|
datapackRecipeMap.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author embeddedt
|
||||||
|
* @reason As we start materializing the final recipe objects, null out the JSON references so we avoid having
|
||||||
|
* to keep both in memory at the same time
|
||||||
|
*/
|
||||||
|
@Inject(method = "createRecipe", at = @At("RETURN"), remap = false)
|
||||||
|
private void modernfix$clearJson(RecipeJS r, CallbackInfoReturnable<Recipe<?>> cir) {
|
||||||
|
if (!ModernFixEarlyConfig.ACTIVE_FEATURE_LEVEL.isAtLeast(FeatureLevel.BETA)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
r.json = null;
|
||||||
|
r.originalJson = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user