Paper/Spigot-Server-Patches/0274-Optimize-RegistryMaterials.patch
Mariell a0b8b886c8
Updated Upstream (CraftBukkit/Spigot) (#4318)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

CraftBukkit Changes:
d5a72960 SPIGOT-6063: ConsoleSender sending extra lines in Java 13+

Spigot Changes:
2740d5ae Rebuild patches
2020-09-12 15:57:21 -04:00

62 lines
3.2 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 RegistryMaterials
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/server/RegistryMaterials.java b/src/main/java/net/minecraft/server/RegistryMaterials.java
index 6000711dd40628bd80a681e63c053a403c88a883..b9de548c9049fca7a24b5259b6c9a01fca0f16ae 100644
--- a/src/main/java/net/minecraft/server/RegistryMaterials.java
+++ b/src/main/java/net/minecraft/server/RegistryMaterials.java
@@ -26,6 +26,7 @@ import java.util.OptionalInt;
import java.util.Random;
import java.util.Set;
import javax.annotation.Nullable;
+import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap; // Paper
import org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -34,7 +35,7 @@ public class RegistryMaterials<T> extends IRegistryWritable<T> {
protected static final Logger LOGGER = LogManager.getLogger();
private final ObjectList<T> bf = new ObjectArrayList(256);
- private final Object2IntMap<T> bg = new Object2IntOpenCustomHashMap(SystemUtils.k());
+ private final Reference2IntOpenHashMap<T> bg = new Reference2IntOpenHashMap<T>(2048);// Paper - use bigger expected size to reduce collisions and direct intent for FastUtil to be identity map
private final BiMap<MinecraftKey, T> bh;
private final BiMap<ResourceKey<T>, T> bi;
private final Map<T, Lifecycle> bj;
@@ -45,9 +46,9 @@ public class RegistryMaterials<T> extends IRegistryWritable<T> {
public RegistryMaterials(ResourceKey<? extends IRegistry<T>> resourcekey, Lifecycle lifecycle) {
super(resourcekey, lifecycle);
this.bg.defaultReturnValue(-1);
- this.bh = HashBiMap.create();
- this.bi = HashBiMap.create();
- this.bj = Maps.newIdentityHashMap();
+ this.bh = HashBiMap.create(2048); // Paper - use bigger expected size to reduce collisions
+ this.bi = HashBiMap.create(2048); // Paper - use bigger expected size to reduce collisions
+ this.bj = new java.util.IdentityHashMap<>(2048); // Paper - use bigger expected size to reduce collisions
this.bk = lifecycle;
}
@@ -191,7 +192,7 @@ public class RegistryMaterials<T> extends IRegistryWritable<T> {
this.b = collection.toArray(new Object[collection.size()]);
}
- return SystemUtils.a(this.b, random);
+ return (T) SystemUtils.a(this.b, random); // Paper - Decompile fix
}
public static <T> Codec<RegistryMaterials<T>> a(ResourceKey<? extends IRegistry<T>> resourcekey, Lifecycle lifecycle, Codec<T> codec) {
@@ -211,7 +212,7 @@ public class RegistryMaterials<T> extends IRegistryWritable<T> {
Iterator iterator = registrymaterials.iterator();
while (iterator.hasNext()) {
- T t0 = iterator.next();
+ T t0 = (T) iterator.next(); // Paper - Decompile fix
builder.add(new RegistryMaterials.a<>((ResourceKey) registrymaterials.c(t0).get(), registrymaterials.a(t0), t0));
}