mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
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.
This commit is contained in:
parent
b9744db06b
commit
eee1fedc1e
2 changed files with 84 additions and 45 deletions
84
Spigot-Server-Patches/Optimize-DataBits.patch
Normal file
84
Spigot-Server-Patches/Optimize-DataBits.patch
Normal file
|
@ -0,0 +1,84 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/DataBits.java
|
||||
+++ b/src/main/java/net/minecraft/server/DataBits.java
|
||||
@@ -0,0 +0,0 @@ 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) {
|
||||
@@ -0,0 +0,0 @@ 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;
|
||||
|
||||
@@ -0,0 +0,0 @@ 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;
|
||||
@@ -0,0 +0,0 @@ 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;
|
||||
@@ -0,0 +0,0 @@ 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;
|
|
@ -1,45 +0,0 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/DataBits.java
|
||||
+++ b/src/main/java/net/minecraft/server/DataBits.java
|
||||
@@ -0,0 +0,0 @@ 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;
|
||||
@@ -0,0 +0,0 @@ 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;
|
||||
@@ -0,0 +0,0 @@ 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;
|
Loading…
Reference in a new issue