From 608b5e52353523c579c0467cb2ee0f91106108d6 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 23 Jul 2018 12:58:01 -0400 Subject: [PATCH 1/2] 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) + From 0069113b2e7e1a0d914011afe2a6ded58db81d0f Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 23 Jul 2018 13:10:06 -0400 Subject: [PATCH 2/2] Put the decompile fixes into MC Dev Fixes patch --- .../0008-Add-PlayerLocaleChangeEvent.patch | 4 +- .../0009-Add-player-view-distance-API.patch | 4 +- .../0010-Add-BeaconEffectEvent.patch | 4 +- Spigot-Server-Patches/0003-MC-Dev-fixes.patch | 51 +++++++++++++++++-- .../0307-Optimize-RegistryID.c.patch | 51 ++++--------------- 5 files changed, 63 insertions(+), 51 deletions(-) diff --git a/Spigot-API-Patches/0008-Add-PlayerLocaleChangeEvent.patch b/Spigot-API-Patches/0008-Add-PlayerLocaleChangeEvent.patch index d9c29d832..7a86be32a 100644 --- a/Spigot-API-Patches/0008-Add-PlayerLocaleChangeEvent.patch +++ b/Spigot-API-Patches/0008-Add-PlayerLocaleChangeEvent.patch @@ -1,4 +1,4 @@ -From 501e01d868ec3f41f8aa3a1bebc83b4305723b42 Mon Sep 17 00:00:00 2001 +From 2ee52b020013ad95861d196908450fa2fc227431 Mon Sep 17 00:00:00 2001 From: Isaac Moore Date: Mon, 29 Feb 2016 18:02:25 -0600 Subject: [PATCH] Add PlayerLocaleChangeEvent @@ -61,5 +61,5 @@ index 00000000..29dd763a + } +} -- -2.18.0 +2.17.0 (Apple Git-106) diff --git a/Spigot-API-Patches/0009-Add-player-view-distance-API.patch b/Spigot-API-Patches/0009-Add-player-view-distance-API.patch index 8f757a13b..99cea1def 100644 --- a/Spigot-API-Patches/0009-Add-player-view-distance-API.patch +++ b/Spigot-API-Patches/0009-Add-player-view-distance-API.patch @@ -1,4 +1,4 @@ -From a046e06ee22190a42f8ec203d7b106a9271c09f2 Mon Sep 17 00:00:00 2001 +From 3308624206985251b7646042a4276f026c169c0b Mon Sep 17 00:00:00 2001 From: Byteflux Date: Mon, 29 Feb 2016 18:05:37 -0600 Subject: [PATCH] Add player view distance API @@ -30,5 +30,5 @@ index 25e44028..7f215f1a 100644 public class Spigot extends Entity.Spigot { -- -2.18.0 +2.17.0 (Apple Git-106) diff --git a/Spigot-API-Patches/0010-Add-BeaconEffectEvent.patch b/Spigot-API-Patches/0010-Add-BeaconEffectEvent.patch index ad3b9b75c..f214a0e8a 100644 --- a/Spigot-API-Patches/0010-Add-BeaconEffectEvent.patch +++ b/Spigot-API-Patches/0010-Add-BeaconEffectEvent.patch @@ -1,4 +1,4 @@ -From e9e1ec6471574850b8eb0cd61bb019a05d7adbb2 Mon Sep 17 00:00:00 2001 +From b0d2313841c2f617773d33708aaca8fece34d75c Mon Sep 17 00:00:00 2001 From: Byteflux Date: Mon, 29 Feb 2016 18:09:40 -0600 Subject: [PATCH] Add BeaconEffectEvent @@ -92,5 +92,5 @@ index 00000000..6579ae99 + } +} -- -2.18.0 +2.17.0 (Apple Git-106) diff --git a/Spigot-Server-Patches/0003-MC-Dev-fixes.patch b/Spigot-Server-Patches/0003-MC-Dev-fixes.patch index 594c48a31..2bc8423b7 100644 --- a/Spigot-Server-Patches/0003-MC-Dev-fixes.patch +++ b/Spigot-Server-Patches/0003-MC-Dev-fixes.patch @@ -1,11 +1,11 @@ -From 1b41bf7f810b3bd6c90db0a7c4ee15776bc6f832 Mon Sep 17 00:00:00 2001 +From fa5eced3c89ff7fa1b290628a381d1211606e2bb Mon Sep 17 00:00:00 2001 From: Aikar Date: Wed, 30 Mar 2016 19:36:20 -0400 Subject: [PATCH] MC Dev fixes diff --git a/src/main/java/com/destroystokyo/paper/PaperCommand.java b/src/main/java/com/destroystokyo/paper/PaperCommand.java -index e8f7b7292..a0ebc1eaa 100644 +index e8f7b729..a0ebc1ea 100644 --- a/src/main/java/com/destroystokyo/paper/PaperCommand.java +++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java @@ -234,4 +234,5 @@ public class PaperCommand extends Command { @@ -15,7 +15,7 @@ index e8f7b7292..a0ebc1eaa 100644 + } diff --git a/src/main/java/net/minecraft/server/BlockPosition.java b/src/main/java/net/minecraft/server/BlockPosition.java -index 002da2a19..121a137f3 100644 +index 002da2a1..121a137f 100644 --- a/src/main/java/net/minecraft/server/BlockPosition.java +++ b/src/main/java/net/minecraft/server/BlockPosition.java @@ -150,7 +150,7 @@ public class BlockPosition extends BaseBlockPosition { @@ -57,7 +57,7 @@ index 002da2a19..121a137f3 100644 } diff --git a/src/main/java/net/minecraft/server/DefinedStructure.java b/src/main/java/net/minecraft/server/DefinedStructure.java -index 65910508f..15c7cc170 100644 +index a661789c..785a1a21 100644 --- a/src/main/java/net/minecraft/server/DefinedStructure.java +++ b/src/main/java/net/minecraft/server/DefinedStructure.java @@ -88,7 +88,7 @@ public class DefinedStructure { @@ -111,6 +111,47 @@ index 65910508f..15c7cc170 100644 } public Iterator iterator() { +diff --git a/src/main/java/net/minecraft/server/RegistryID.java b/src/main/java/net/minecraft/server/RegistryID.java +index 3b8f6ec1..bde5714d 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; +@@ -17,9 +17,9 @@ public class RegistryID implements Registry { + + 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 + } + + public int getId(@Nullable K k0) { +@@ -51,12 +51,12 @@ public class RegistryID implements Registry { + } + + 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; + -- -2.17.1 +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 index a06d7c2a1..e3bfc98a0 100644 --- a/Spigot-Server-Patches/0307-Optimize-RegistryID.c.patch +++ b/Spigot-Server-Patches/0307-Optimize-RegistryID.c.patch @@ -1,24 +1,15 @@ -From 94b336dd8e491cde34799f4d46335497690a2032 Mon Sep 17 00:00:00 2001 +From 48a1b1c1f5b4572ab2ade1314c35c9508d3644ea Mon Sep 17 00:00:00 2001 From: Andrew Steinborn -Date: Mon, 23 Jul 2018 12:50:18 -0400 +Date: Mon, 23 Jul 2018 13:08:19 -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 +index bde5714d..a01cda9d 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 { +@@ -14,12 +14,14 @@ public class RegistryID implements Registry { // Paper - decompile fix private K[] d; private int e; private int f; @@ -26,16 +17,14 @@ index 3b8f6ec1..163da432 100644 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.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.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 { +@@ -43,9 +45,14 @@ public class RegistryID implements Registry { // Paper - decompile fix } private int c() { @@ -50,33 +39,15 @@ index 3b8f6ec1..163da432 100644 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 +@@ -59,6 +66,7 @@ public class RegistryID implements Registry { // Paper - decompile fix + 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 { +@@ -84,6 +92,7 @@ public class RegistryID implements Registry { // Paper - decompile fix this.b[k] = k0; this.c[k] = i; this.d[i] = k0; @@ -84,7 +55,7 @@ index 3b8f6ec1..163da432 100644 ++this.f; if (i == this.e) { ++this.e; -@@ -148,6 +157,7 @@ public class RegistryID implements Registry { +@@ -148,6 +157,7 @@ public class RegistryID implements Registry { // Paper - decompile fix Arrays.fill(this.d, (Object) null); this.e = 0; this.f = 0;