Cache BlockModelShaper.statePropertiesToString

This commit is contained in:
embeddedt 2023-03-11 09:38:06 -05:00
parent c481ae0f26
commit 14e266288a
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,26 @@
package org.embeddedt.modernfix.mixin.perf.parallelize_model_loading;
import com.google.common.collect.Interner;
import com.google.common.collect.Interners;
import net.minecraft.client.renderer.block.BlockModelShaper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Mixin(BlockModelShaper.class)
public class BlockModelShaperMixin {
private static Map<BlockState, String> stateToPropertiesCache = new ConcurrentHashMap<>();
@Redirect(method = "stateToModelLocation(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/client/resources/model/ModelResourceLocation;",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/block/BlockModelShaper;statePropertiesToString(Ljava/util/Map;)Ljava/lang/String;"))
private static String getCachedProperty(Map<Property<?>, Comparable<?>> values, ResourceLocation location, BlockState state) {
/* We intentionally don't use the values parameter inside the lambda to avoid an allocation */
return stateToPropertiesCache.computeIfAbsent(state, s -> BlockModelShaper.statePropertiesToString(s.getValues()));
}
}

View File

@ -65,6 +65,7 @@
"bugfix.concurrency.RenderTypeMixin",
"bugfix.concurrency.MinecraftMixin",
"bugfix.concurrency.StaticTagHelperMixin",
"perf.parallelize_model_loading.BlockModelShaperMixin",
"perf.parallelize_model_loading.ModelBakeryMixin",
"perf.parallelize_model_loading.OBJLoaderMixin",
"perf.parallelize_model_loading.multipart.MultipartMixin",