From 0eaffd00828b7283fa23b54e91e333c9ba5a0078 Mon Sep 17 00:00:00 2001 From: Aikar Date: Wed, 30 Dec 2020 14:02:44 -0500 Subject: [PATCH] Micro Optimize DataBits There was 2 unnecessary lines of code in a core method used for DataBits that repeatedly calculated a static value. We now just precalculate that in the constructor and reuse the value instead. This is a micro optimization, but this is some of the hottest code in the server so it should provide some minor gains as well as improve inlining. Additionally, to further help inlining, mark the DataBits methods as final. --- .../0081-Optimize-DataBits.patch | 84 +++++++++++++++++++ ...81-Remove-Debug-checks-from-DataBits.patch | 45 ---------- 2 files changed, 84 insertions(+), 45 deletions(-) create mode 100644 Spigot-Server-Patches/0081-Optimize-DataBits.patch delete mode 100644 Spigot-Server-Patches/0081-Remove-Debug-checks-from-DataBits.patch diff --git a/Spigot-Server-Patches/0081-Optimize-DataBits.patch b/Spigot-Server-Patches/0081-Optimize-DataBits.patch new file mode 100644 index 000000000..8b7f3a150 --- /dev/null +++ b/Spigot-Server-Patches/0081-Optimize-DataBits.patch @@ -0,0 +1,84 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Tue, 5 Apr 2016 21:38:58 -0400 +Subject: [PATCH] Optimize DataBits + +Remove Debug checks as these are super hot and causing noticeable hits + +Before: http://i.imgur.com/nQsMzAE.png +After: http://i.imgur.com/nJ46crB.png + +Optimize redundant converting of static fields into an unsigned long each call by precomputing it in ctor + +diff --git a/src/main/java/net/minecraft/server/DataBits.java b/src/main/java/net/minecraft/server/DataBits.java +index 53e7bac2f7a99238f509bb0f871ebed103fda568..2a01a48ad347fb123492218a60404b034cfcfbc5 100644 +--- a/src/main/java/net/minecraft/server/DataBits.java ++++ b/src/main/java/net/minecraft/server/DataBits.java +@@ -12,8 +12,8 @@ public class DataBits { + private final long d; + private final int e; + private final int f; +- private final int g; +- private final int h; ++ private final int g;private final long g_unsigned; // Paper - referenced in b(int) with 2 Integer.toUnsignedLong calls ++ private final int h;private final long h_unsigned; // Paper + private final int i; + + public DataBits(int i, int j) { +@@ -28,8 +28,8 @@ public class DataBits { + this.f = (char) (64 / i); + int k = 3 * (this.f - 1); + +- this.g = DataBits.a[k + 0]; +- this.h = DataBits.a[k + 1]; ++ this.g = DataBits.a[k + 0]; this.g_unsigned = Integer.toUnsignedLong(this.g); // Paper ++ this.h = DataBits.a[k + 1]; this.h_unsigned = Integer.toUnsignedLong(this.h); // Paper + this.i = DataBits.a[k + 2]; + int l = (j + this.f - 1) / this.f; + +@@ -46,15 +46,15 @@ public class DataBits { + } + + private int b(int i) { +- long j = Integer.toUnsignedLong(this.g); +- long k = Integer.toUnsignedLong(this.h); ++ //long j = Integer.toUnsignedLong(this.g); // Paper ++ //long k = Integer.toUnsignedLong(this.h); // Paper + +- return (int) ((long) i * j + k >> 32 >> this.i); ++ return (int) ((long) i * this.g_unsigned + this.h_unsigned >> 32 >> this.i); // Paper + } + +- public int a(int i, int j) { +- Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) i); +- Validate.inclusiveBetween(0L, this.d, (long) j); ++ public final int a(int i, int j) { // Paper - make final for inline ++ //Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) i); // Paper ++ //Validate.inclusiveBetween(0L, this.d, (long) j); // Paper + int k = this.b(i); + long l = this.b[k]; + int i1 = (i - k * this.f) * this.c; +@@ -64,9 +64,9 @@ public class DataBits { + return j1; + } + +- public void b(int i, int j) { +- Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) i); +- Validate.inclusiveBetween(0L, this.d, (long) j); ++ public final void b(int i, int j) { // Paper - make final for inline ++ //Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) i); // Paper ++ //Validate.inclusiveBetween(0L, this.d, (long) j); // Paper + int k = this.b(i); + long l = this.b[k]; + int i1 = (i - k * this.f) * this.c; +@@ -74,8 +74,8 @@ public class DataBits { + this.b[k] = l & ~(this.d << i1) | ((long) j & this.d) << i1; + } + +- public int a(int i) { +- Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) i); ++ public final int a(int i) { // Paper - make final for inline ++ //Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) i); // Paper + int j = this.b(i); + long k = this.b[j]; + int l = (i - j * this.f) * this.c; diff --git a/Spigot-Server-Patches/0081-Remove-Debug-checks-from-DataBits.patch b/Spigot-Server-Patches/0081-Remove-Debug-checks-from-DataBits.patch deleted file mode 100644 index 005e25c37..000000000 --- a/Spigot-Server-Patches/0081-Remove-Debug-checks-from-DataBits.patch +++ /dev/null @@ -1,45 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Aikar -Date: Tue, 5 Apr 2016 21:38:58 -0400 -Subject: [PATCH] Remove Debug checks from DataBits - -These are super hot and causing noticeable hits - -Before: http://i.imgur.com/nQsMzAE.png -After: http://i.imgur.com/nJ46crB.png - -diff --git a/src/main/java/net/minecraft/server/DataBits.java b/src/main/java/net/minecraft/server/DataBits.java -index 53e7bac2f7a99238f509bb0f871ebed103fda568..2901700dc0ff5dce4fb6f6df9f6686c786293d28 100644 ---- a/src/main/java/net/minecraft/server/DataBits.java -+++ b/src/main/java/net/minecraft/server/DataBits.java -@@ -53,8 +53,8 @@ public class DataBits { - } - - public int a(int i, int j) { -- Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) i); -- Validate.inclusiveBetween(0L, this.d, (long) j); -+ //Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) i); // Paper -+ //Validate.inclusiveBetween(0L, this.d, (long) j); // Paper - int k = this.b(i); - long l = this.b[k]; - int i1 = (i - k * this.f) * this.c; -@@ -65,8 +65,8 @@ public class DataBits { - } - - public void b(int i, int j) { -- Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) i); -- Validate.inclusiveBetween(0L, this.d, (long) j); -+ //Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) i); // Paper -+ //Validate.inclusiveBetween(0L, this.d, (long) j); // Paper - int k = this.b(i); - long l = this.b[k]; - int i1 = (i - k * this.f) * this.c; -@@ -75,7 +75,7 @@ public class DataBits { - } - - public int a(int i) { -- Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) i); -+ //Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) i); // Paper - int j = this.b(i); - long k = this.b[j]; - int l = (i - j * this.f) * this.c;