mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-06 02:42:14 +01:00
0eaffd0082
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.
85 lines
3.5 KiB
Diff
85 lines
3.5 KiB
Diff
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 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;
|