From a45783647fc199d4b08c9cc6575cce314790ad6a Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:37:50 -0500 Subject: [PATCH 1/2] Make the block model cache thread-local instead of using a lock --- .../BlockModelShaperMixin.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/BlockModelShaperMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/BlockModelShaperMixin.java index bed4cb16..11f99989 100644 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/BlockModelShaperMixin.java +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/BlockModelShaperMixin.java @@ -1,12 +1,12 @@ package org.embeddedt.modernfix.common.mixin.perf.dynamic_resources; +import it.unimi.dsi.fastutil.objects.Reference2ReferenceLinkedOpenHashMap; import net.minecraft.client.renderer.block.BlockModelShaper; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.ModelManager; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.world.level.block.state.BlockState; import org.embeddedt.modernfix.annotation.ClientOnlyMixin; -import org.embeddedt.modernfix.dynamicresources.DynamicModelCache; import org.embeddedt.modernfix.dynamicresources.ModelLocationCache; import org.embeddedt.modernfix.util.DynamicOverridableMap; import org.spongepowered.asm.mixin.*; @@ -25,7 +25,7 @@ public class BlockModelShaperMixin { @Shadow @Final @Mutable private Map modelByStateCache; - private final DynamicModelCache mfix$modelCache = new DynamicModelCache<>(k -> this.cacheBlockModel((BlockState)k), false); + private ThreadLocal> mfix$modelCache = ThreadLocal.withInitial(Reference2ReferenceLinkedOpenHashMap::new); @Inject(method = "", at = @At("RETURN")) private void replaceModelMap(CallbackInfo ci) { @@ -39,7 +39,7 @@ public class BlockModelShaperMixin { */ @Overwrite public void rebuildCache() { - this.mfix$modelCache.clear(); + this.mfix$modelCache = ThreadLocal.withInitial(Reference2ReferenceLinkedOpenHashMap::new); } private BakedModel cacheBlockModel(BlockState state) { @@ -59,6 +59,18 @@ public class BlockModelShaperMixin { */ @Overwrite public BakedModel getBlockModel(BlockState state) { - return this.mfix$modelCache.get(state); + Reference2ReferenceLinkedOpenHashMap map = this.mfix$modelCache.get(); + BakedModel model = map.get(state); + + if(model != null) { + return model; + } + + model = this.cacheBlockModel(state); + map.putAndMoveToFirst(state, model); + if(map.size() > 500) { + map.removeLast(); + } + return model; } } From 40b9ac6002467f737a87b201fcf662005525b45f Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Fri, 8 Mar 2024 17:49:46 -0500 Subject: [PATCH 2/2] Disable pose stack bugfix when OptiFine is installed Related: #376 --- .../embeddedt/modernfix/core/config/ModernFixEarlyConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java b/common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java index 65696139..b86c734c 100644 --- a/common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java +++ b/common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java @@ -228,6 +228,7 @@ public class ModernFixEarlyConfig { disableIfModPresent("mixin.perf.reuse_datapacks", "tac"); disableIfModPresent("mixin.launch.class_search_cache", "optifine"); disableIfModPresent("mixin.perf.faster_texture_stitching", "optifine"); + disableIfModPresent("mixin.bugfix.entity_pose_stack", "optifine"); disableIfModPresent("mixin.perf.datapack_reload_exceptions", "cyanide"); disableIfModPresent("mixin.perf.faster_texture_loading", "stitch", "optifine", "changed"); if(isFabric) {