From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sun, 26 Aug 2018 20:49:50 -0400 Subject: [PATCH] Optimize MappedRegistry Use larger initial sizes to increase bucket capacity on the BiMap BiMap.get was seen to be using a good bit of CPU time. diff --git a/src/main/java/net/minecraft/core/MappedRegistry.java b/src/main/java/net/minecraft/core/MappedRegistry.java index 3b9eb0d19623a8a8e60f785edfd2faadba54ce84..0ae87b1ee3373a7eead633fa2a85d64f8d88bcaf 100644 --- a/src/main/java/net/minecraft/core/MappedRegistry.java +++ b/src/main/java/net/minecraft/core/MappedRegistry.java @@ -38,12 +38,10 @@ public class MappedRegistry extends WritableRegistry { protected static final Logger LOGGER = LogManager.getLogger(); private final ObjectList byId = new ObjectArrayList(256); - private final Object2IntMap toId = (Object2IntMap) Util.make(new Object2IntOpenCustomHashMap(Util.identityStrategy()), (object2intopencustomhashmap) -> { - object2intopencustomhashmap.defaultReturnValue(-1); - }); - private final BiMap storage = HashBiMap.create(); - private final BiMap, T> keyStorage = HashBiMap.create(); - private final Map lifecycles = Maps.newIdentityHashMap(); + private final it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap toId = new it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap(2048);// Paper - use bigger expected size to reduce collisions and direct intent for FastUtil to be identity map + private final BiMap storage = HashBiMap.create(2048); // Paper - use bigger expected size to reduce collisions + private final BiMap, T> keyStorage = HashBiMap.create(2048); // Paper - use bigger expected size to reduce collisions + private final Map lifecycles = new java.util.IdentityHashMap<>(2048); // Paper - use bigger expected size to reduce collisions private Lifecycle elementsLifecycle; @Nullable protected Object[] randomCache; @@ -52,6 +50,7 @@ public class MappedRegistry extends WritableRegistry { public MappedRegistry(ResourceKey> key, Lifecycle lifecycle) { super(key, lifecycle); this.elementsLifecycle = lifecycle; + this.toId.defaultReturnValue(-1); // Paper } public static MapCodec> withNameAndId(ResourceKey> key, MapCodec entryCodec) {