Skip to content

Commit 51c4f3e

Browse files
committed
Use smarter iteration order in model bake event registry
This heavily improves the rate of cache hits when mods are baking many variants of the same model via iteration over the keys, as now all the variants will be obtained at once rather than being retrieved randomly. Cable Tiers used to take 8 seconds in the event before this change on a Ryzen 7700X, and is now nearly instant.
1 parent 455b567 commit 51c4f3e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

forge/src/main/java/org/embeddedt/modernfix/forge/dynresources/ModelBakeEventHelper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.google.common.collect.Sets;
77
import com.google.common.graph.GraphBuilder;
88
import com.google.common.graph.MutableGraph;
9+
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
910
import net.minecraft.client.renderer.block.BlockModelShaper;
1011
import net.minecraft.client.resources.model.BakedModel;
1112
import net.minecraft.client.resources.model.ModelBakery;
@@ -54,7 +55,7 @@ public class ModelBakeEventHelper {
5455
private final MutableGraph<String> dependencyGraph;
5556
public ModelBakeEventHelper(Map<ResourceLocation, BakedModel> modelRegistry) {
5657
this.modelRegistry = modelRegistry;
57-
this.topLevelModelLocations = new HashSet<>(modelRegistry.keySet());
58+
this.topLevelModelLocations = new ObjectLinkedOpenHashSet<>();
5859
// Skip going through ModelLocationCache because most of the accesses will be misses
5960
ForgeRegistries.BLOCKS.getEntries().forEach(entry -> {
6061
var location = entry.getKey().location();
@@ -63,6 +64,7 @@ public ModelBakeEventHelper(Map<ResourceLocation, BakedModel> modelRegistry) {
6364
}
6465
});
6566
ForgeRegistries.ITEMS.getKeys().forEach(key -> topLevelModelLocations.add(new ModelResourceLocation(key, "inventory")));
67+
this.topLevelModelLocations.addAll(modelRegistry.keySet());
6668
this.dependencyGraph = GraphBuilder.undirected().build();
6769
ModList.get().forEachModContainer((id, mc) -> {
6870
this.dependencyGraph.addNode(id);

0 commit comments

Comments
 (0)