2019-07-20 12:01:24 +08:00
|
|
|
From 291b4375927c5222ac23894c0a96013055bce0bc Mon Sep 17 00:00:00 2001
|
2018-08-27 02:11:49 +08:00
|
|
|
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
|
2019-07-20 12:01:24 +08:00
|
|
|
index f291e05b26..fed38e6ef0 100644
|
2018-08-27 02:11:49 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/RegistryMaterials.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/RegistryMaterials.java
|
2019-05-05 16:33:44 +08:00
|
|
|
@@ -16,9 +16,9 @@ import org.apache.logging.log4j.Logger;
|
|
|
|
public class RegistryMaterials<T> extends IRegistryWritable<T> {
|
2019-01-01 11:15:55 +08:00
|
|
|
|
2019-05-05 16:33:44 +08:00
|
|
|
protected static final Logger LOGGER = LogManager.getLogger();
|
|
|
|
- protected final RegistryID<T> b = new RegistryID<>(256);
|
|
|
|
- protected final BiMap<MinecraftKey, T> c = HashBiMap.create();
|
2019-01-01 11:15:55 +08:00
|
|
|
- protected Object[] d;
|
2019-05-05 16:33:44 +08:00
|
|
|
+ protected final RegistryID<T> b = new RegistryID<>(2048); // Paper - use bigger expected size to reduce collisions
|
|
|
|
+ protected final BiMap<MinecraftKey, T> c = HashBiMap.create(2048); // Paper - use bigger expected size to reduce collisions
|
|
|
|
+ protected T[] d; // Paper - Decompile fix
|
|
|
|
private int R;
|
2018-08-27 02:11:49 +08:00
|
|
|
|
2019-01-01 11:15:55 +08:00
|
|
|
public RegistryMaterials() {}
|
2019-05-05 16:33:44 +08:00
|
|
|
@@ -98,7 +98,7 @@ public class RegistryMaterials<T> extends IRegistryWritable<T> {
|
2019-01-01 11:15:55 +08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
- this.d = collection.toArray(new Object[collection.size()]);
|
2019-05-06 15:20:16 +08:00
|
|
|
+ this.d = (T[]) collection.toArray(new Object[collection.size()]); // Paper - Decompile fix
|
2019-01-01 11:15:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.d[random.nextInt(this.d.length)];
|
2018-08-27 02:11:49 +08:00
|
|
|
--
|
2019-06-26 03:18:50 +08:00
|
|
|
2.22.0
|
2018-08-27 02:11:49 +08:00
|
|
|
|