Minor performance improvements to model handling

This commit is contained in:
embeddedt 2023-02-12 09:38:32 -05:00
parent 6c7fd44f00
commit 02d9311040
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
4 changed files with 42 additions and 26 deletions

View File

@ -6,6 +6,7 @@ import org.embeddedt.modernfix.ModernFix;
public class IdentifierCaches {
public static final DeduplicationCache<String> NAMESPACES = new DeduplicationCache<>();
public static final DeduplicationCache<String> PATH = new DeduplicationCache<>();
public static final DeduplicationCache<String> PROPERTY = new DeduplicationCache<>();
public static void printDebug() {
ModernFix.LOGGER.info("[[[ Identifier de-duplication statistics ]]]");

View File

@ -1,22 +1,15 @@
package org.embeddedt.modernfix.mixin.perf.parallelize_model_loading;
import com.google.common.base.Stopwatch;
import com.google.common.collect.Sets;
import com.mojang.datafixers.util.Pair;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockModelShapes;
import net.minecraft.client.renderer.model.*;
import net.minecraft.client.renderer.model.multipart.Selector;
import net.minecraft.client.renderer.texture.SpriteMap;
import net.minecraft.profiler.IProfiler;
import net.minecraft.resources.IResource;
import net.minecraft.resources.IResourceManager;
import net.minecraft.state.StateContainer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Util;
import net.minecraft.util.math.vector.TransformationMatrix;
import net.minecraft.util.registry.Registry;
import net.minecraftforge.fml.loading.progress.StartupMessageManager;
import org.embeddedt.modernfix.ModernFix;
@ -26,13 +19,8 @@ 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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -40,25 +28,11 @@ import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Mixin(ModelBakery.class)
public abstract class ModelBakeryMixin {
@Shadow protected abstract BlockModel loadBlockModel(ResourceLocation location) throws IOException;
@Shadow @Final private Map<ResourceLocation, IUnbakedModel> unbakedCache;
@Shadow @Final public static ModelResourceLocation MISSING_MODEL_LOCATION;
@Shadow public abstract IUnbakedModel getModel(ResourceLocation modelLocation);
@Shadow @Final private Map<ResourceLocation, IUnbakedModel> topLevelModels;
@Shadow @Final protected IResourceManager resourceManager;
private Map<ResourceLocation, List<Pair<String, BlockModelDefinition>>> deserializedBlockstateCache = null;

View File

@ -0,0 +1,40 @@
package org.embeddedt.modernfix.mixin.perf.parallelize_model_loading;
import net.minecraft.state.Property;
import org.embeddedt.modernfix.dedup.IdentifierCaches;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(Property.class)
public class PropertyMixin {
@Shadow @Mutable
@Final private String name;
@Shadow private Integer hashCode;
@Shadow @Final private Class clazz;
@Redirect(method = "<init>", at = @At(value = "FIELD", target = "Lnet/minecraft/state/Property;name:Ljava/lang/String;"))
private void internName(Property instance, String name) {
this.name = IdentifierCaches.PROPERTY.deduplicate(name);
}
/**
* @author embeddedt
* @reason compare hashcodes if generated, use reference equality for speed
*/
@Overwrite
public boolean equals(Object p_equals_1_) {
if (this == p_equals_1_) {
return true;
} else if (!(p_equals_1_ instanceof Property)) {
return false;
} else {
Property<?> property = (Property)p_equals_1_;
/* reference equality is safe here because of deduplication */
return this.clazz == property.getValueClass() && this.name == property.getName();
}
}
}

View File

@ -42,6 +42,7 @@
"perf.parallelize_model_loading.SelectorMixin",
"perf.parallelize_model_loading.TransformationMatrixMixin",
"perf.parallelize_model_loading.BooleanPropertyMixin",
"perf.parallelize_model_loading.PropertyMixin",
"perf.async_jei.IngredientListElementFactoryMixin",
"perf.async_jei.ClientLifecycleHandlerMixin",
"perf.async_jei.JeiStarterMixin",