mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
60caeea54e
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: d25437bc Update to Minecraft 1.18-pre8 CraftBukkit Changes: 5a39a236 Update to Minecraft 1.18-pre8 Spigot Changes: 7840c2af Update to Minecraft 1.18-pre8
40 lines
2.6 KiB
Diff
40 lines
2.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/core/MappedRegistry.java
|
|
+++ b/src/main/java/net/minecraft/core/MappedRegistry.java
|
|
@@ -0,0 +0,0 @@ import org.apache.logging.log4j.Logger;
|
|
|
|
public class MappedRegistry<T> extends WritableRegistry<T> {
|
|
protected static final Logger LOGGER = LogManager.getLogger();
|
|
- private final ObjectList<T> byId = new ObjectArrayList<>(256);
|
|
- private final Object2IntMap<T> toId = Util.make(new Object2IntOpenCustomHashMap<>(Util.identityStrategy()), (object2IntOpenCustomHashMap) -> {
|
|
- object2IntOpenCustomHashMap.defaultReturnValue(-1);
|
|
- });
|
|
- private final BiMap<ResourceLocation, T> storage = HashBiMap.create();
|
|
- private final BiMap<ResourceKey<T>, T> keyStorage = HashBiMap.create();
|
|
- private final Map<T, Lifecycle> lifecycles = Maps.newIdentityHashMap();
|
|
+ private final ObjectList<T> byId = new ObjectArrayList(256);
|
|
+ private final it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap<T> toId = new it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap<T>(2048);// Paper - use bigger expected size to reduce collisions and direct intent for FastUtil to be identity map
|
|
+ private final BiMap<ResourceLocation, T> storage = HashBiMap.create(2048); // Paper - use bigger expected size to reduce collisions
|
|
+ private final BiMap<ResourceKey<T>, T> keyStorage = HashBiMap.create(2048); // Paper - use bigger expected size to reduce collisions
|
|
+ private final Map<T, Lifecycle> lifecycles = new java.util.IdentityHashMap<>(2048); // Paper - use bigger expected size to reduce collisions
|
|
private Lifecycle elementsLifecycle;
|
|
@Nullable
|
|
protected Object[] randomCache;
|
|
@@ -0,0 +0,0 @@ public class MappedRegistry<T> extends WritableRegistry<T> {
|
|
public MappedRegistry(ResourceKey<? extends Registry<T>> key, Lifecycle lifecycle) {
|
|
super(key, lifecycle);
|
|
this.elementsLifecycle = lifecycle;
|
|
+ this.toId.defaultReturnValue(-1); // Paper
|
|
}
|
|
|
|
public static <T> MapCodec<MappedRegistry.RegistryEntry<T>> withNameAndId(ResourceKey<? extends Registry<T>> key, MapCodec<T> entryCodec) {
|