From 608b5e52353523c579c0467cb2ee0f91106108d6 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 --- .../0015-Player-Tab-List-and-Title-APIs.patch | 4 +- .../0307-Optimize-RegistryID.c.patch | 97 +++++++++++++++++++ 2 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 Spigot-Server-Patches/0307-Optimize-RegistryID.c.patch diff --git a/Spigot-API-Patches/0015-Player-Tab-List-and-Title-APIs.patch b/Spigot-API-Patches/0015-Player-Tab-List-and-Title-APIs.patch index f2677979c..5ae2621d0 100644 --- a/Spigot-API-Patches/0015-Player-Tab-List-and-Title-APIs.patch +++ b/Spigot-API-Patches/0015-Player-Tab-List-and-Title-APIs.patch @@ -1,4 +1,4 @@ -From d9b9cd6fb36cdf689bbe3760147795092a6b111f Mon Sep 17 00:00:00 2001 +From fa4c0456f5dd7abf1913952d44e859ebfdd61069 Mon Sep 17 00:00:00 2001 From: Techcable Date: Mon, 29 Feb 2016 20:02:40 -0600 Subject: [PATCH] Player Tab List and Title APIs @@ -498,5 +498,5 @@ index f4d1ade5..65b7a076 100644 /** -- -2.18.0 +2.17.0 (Apple Git-106) diff --git a/Spigot-Server-Patches/0307-Optimize-RegistryID.c.patch b/Spigot-Server-Patches/0307-Optimize-RegistryID.c.patch new file mode 100644 index 000000000..a06d7c2a1 --- /dev/null +++ b/Spigot-Server-Patches/0307-Optimize-RegistryID.c.patch @@ -0,0 +1,97 @@ +From 94b336dd8e491cde34799f4d46335497690a2032 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 +@@ -6,7 +6,7 @@ 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; +@@ -14,12 +14,14 @@ 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) { +@@ -43,22 +45,28 @@ 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) { +@@ -69,7 +77,7 @@ 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) { +@@ -84,6 +92,7 @@ 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; +@@ -148,6 +157,7 @@ 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) +