From 9399a74c2ac1e0238a1defe904fb882ae1320ad4 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 23 Jul 2018 12:58:01 -0400 Subject: [PATCH] Optimize RegistryID.c() Fixes #1253 --- .../Player-Tab-List-and-Title-APIs.patch | 4 +- .../Optimize-RegistryID.c.patch | 97 +++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 Spigot-Server-Patches/Optimize-RegistryID.c.patch diff --git a/Spigot-API-Patches/Player-Tab-List-and-Title-APIs.patch b/Spigot-API-Patches/Player-Tab-List-and-Title-APIs.patch index ccbd26fd13..0c1908599c 100644 --- a/Spigot-API-Patches/Player-Tab-List-and-Title-APIs.patch +++ b/Spigot-API-Patches/Player-Tab-List-and-Title-APIs.patch @@ -497,4 +497,6 @@ index f4d1ade5..65b7a076 100644 // Paper end /** --- \ No newline at end of file +-- +2.17.0 (Apple Git-106) + diff --git a/Spigot-Server-Patches/Optimize-RegistryID.c.patch b/Spigot-Server-Patches/Optimize-RegistryID.c.patch new file mode 100644 index 0000000000..2d3854aacb --- /dev/null +++ b/Spigot-Server-Patches/Optimize-RegistryID.c.patch @@ -0,0 +1,97 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Andrew Steinborn +Date: Mon, 23 Jul 2018 12:50:18 -0400 +Subject: [PATCH] Optimize RegistryID.c() + +This is a frequent hotspot for world loading/saving. + +diff --git a/src/main/java/net/minecraft/server/RegistryID.java b/src/main/java/net/minecraft/server/RegistryID.java +index 3b8f6ec1..163da432 100644 +--- a/src/main/java/net/minecraft/server/RegistryID.java ++++ b/src/main/java/net/minecraft/server/RegistryID.java +@@ -0,0 +0,0 @@ import java.util.Arrays; + import java.util.Iterator; + import javax.annotation.Nullable; + +-public class RegistryID implements Registry { ++public class RegistryID implements Registry { // Paper - decompile fix + + private static final Object a = null; + private K[] b; +@@ -0,0 +0,0 @@ public class RegistryID implements Registry { + private K[] d; + private int e; + private int f; ++ private java.util.BitSet usedIds; // Paper + + public RegistryID(int i) { + i = (int) ((float) i / 0.8F); +- this.b = (Object[]) (new Object[i]); ++ this.b = (K[]) (new Object[i]); // Paper - decompile fix + this.c = new int[i]; +- this.d = (Object[]) (new Object[i]); ++ this.d = (K[]) (new Object[i]); // Paper - decompile fix ++ this.usedIds = new java.util.BitSet(); // Paper + } + + public int getId(@Nullable K k0) { +@@ -0,0 +0,0 @@ public class RegistryID implements Registry { + } + + private int c() { ++ // Paper start ++ /* + while (this.e < this.d.length && this.d[this.e] != null) { + ++this.e; + } ++ */ ++ this.e = this.usedIds.nextClearBit(0); ++ // Paper end + + return this.e; + } + + private void d(int i) { +- Object[] aobject = this.b; ++ K[] aobject = this.b; // Paper - decompile fix + int[] aint = this.c; + +- this.b = (Object[]) (new Object[i]); ++ this.b = (K[]) (new Object[i]); // Paper - decompile fix + this.c = new int[i]; +- this.d = (Object[]) (new Object[i]); ++ this.d = (K[]) (new Object[i]); // Paper - decompile fix + this.e = 0; + this.f = 0; ++ this.usedIds.clear(); // Paper + + for (int j = 0; j < aobject.length; ++j) { + if (aobject[j] != null) { +@@ -0,0 +0,0 @@ public class RegistryID implements Registry { + } + + public void a(K k0, int i) { +- int j = Math.max(i, this.f + 1); ++ int j = this.usedIds.size(); // Paper + int k; + + if ((float) j >= (float) this.b.length * 0.8F) { +@@ -0,0 +0,0 @@ public class RegistryID implements Registry { + this.b[k] = k0; + this.c[k] = i; + this.d[i] = k0; ++ this.usedIds.set(i); // Paper + ++this.f; + if (i == this.e) { + ++this.e; +@@ -0,0 +0,0 @@ public class RegistryID implements Registry { + Arrays.fill(this.d, (Object) null); + this.e = 0; + this.f = 0; ++ this.usedIds.clear(); // Paper + } + + public int b() { +-- +2.17.0 (Apple Git-106) +