2019-05-14 21:54:32 +00:00
|
|
|
From b5a51584adeb6c21dd7e08e08deaf7a1caa6727e Mon Sep 17 00:00:00 2001
|
2016-12-01 02:57:02 +00:00
|
|
|
From: Techcable <Techcable@outlook.com>
|
|
|
|
Date: Wed, 30 Nov 2016 20:56:58 -0600
|
|
|
|
Subject: [PATCH] Speedup BlockPos by fixing inlining
|
|
|
|
|
|
|
|
Normally the JVM can inline virtual getters by having two sets of code, one is the 'optimized' code and the other is the 'deoptimized' code.
|
|
|
|
If a single type is used 99% of the time, then its worth it to inline, and to revert to 'deoptimized' the 1% of the time we encounter other types.
|
|
|
|
But if two types are encountered commonly, then the JVM can't inline them both, and the call overhead remains.
|
|
|
|
|
|
|
|
This scenario also occurs with BlockPos and MutableBlockPos.
|
|
|
|
The variables in BlockPos are final, so MutableBlockPos can't modify them.
|
|
|
|
MutableBlockPos fixes this by adding custom mutable variables, and overriding the getters to access them.
|
|
|
|
|
|
|
|
This approach with utility methods that operate on MutableBlockPos and BlockPos.
|
|
|
|
Specific examples are BlockPosition.up(), and World.isValidLocation().
|
|
|
|
It makes these simple methods much slower than they need to be.
|
|
|
|
|
|
|
|
This should result in an across the board speedup in anything that accesses blocks or does logic with positions.
|
|
|
|
|
|
|
|
This is based upon conclusions drawn from inspecting the assenmbly generated bythe JIT compiler on my mircorbenchmarks.
|
|
|
|
They had 'callq' (invoke) instead of 'mov' (get from memory) instructions.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/BaseBlockPosition.java b/src/main/java/net/minecraft/server/BaseBlockPosition.java
|
2019-05-14 21:54:32 +00:00
|
|
|
index 7cb46d7a9c..e96428bb2b 100644
|
2016-12-01 02:57:02 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/BaseBlockPosition.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/BaseBlockPosition.java
|
2019-01-01 03:15:55 +00:00
|
|
|
@@ -7,22 +7,22 @@ import javax.annotation.concurrent.Immutable;
|
2016-12-01 02:57:02 +00:00
|
|
|
public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
|
2019-01-01 03:15:55 +00:00
|
|
|
|
2016-12-01 02:57:02 +00:00
|
|
|
public static final BaseBlockPosition ZERO = new BaseBlockPosition(0, 0, 0);
|
|
|
|
- private final int a;
|
|
|
|
- private final int b;
|
|
|
|
- private final int c;
|
2018-07-22 22:46:13 +00:00
|
|
|
// Paper start
|
|
|
|
+ protected int x;
|
|
|
|
+ protected int y;
|
|
|
|
+ protected int z;
|
|
|
|
public boolean isValidLocation() {
|
|
|
|
- return a >= -30000000 && c >= -30000000 && a < 30000000 && c < 30000000 && b >= 0 && b < 256;
|
|
|
|
+ return x >= -30000000 && z >= -30000000 && x < 30000000 && z < 30000000 && y >= 0 && y < 256;
|
2016-12-01 02:57:02 +00:00
|
|
|
}
|
|
|
|
public boolean isInvalidYLocation() {
|
2018-07-22 22:46:13 +00:00
|
|
|
- return b < 0 || b >= 256;
|
|
|
|
+ return y < 0 || y >= 256;
|
|
|
|
}
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
public BaseBlockPosition(int i, int j, int k) {
|
|
|
|
- this.a = i;
|
|
|
|
- this.b = j;
|
|
|
|
- this.c = k;
|
|
|
|
+ this.x = i;
|
|
|
|
+ this.y = j;
|
|
|
|
+ this.z = k;
|
|
|
|
}
|
|
|
|
|
|
|
|
public BaseBlockPosition(double d0, double d1, double d2) {
|
2019-04-30 01:20:24 +00:00
|
|
|
@@ -49,24 +49,26 @@ public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
|
2019-01-01 03:15:55 +00:00
|
|
|
return this.getY() == baseblockposition.getY() ? (this.getZ() == baseblockposition.getZ() ? this.getX() - baseblockposition.getX() : this.getZ() - baseblockposition.getZ()) : this.getY() - baseblockposition.getY();
|
2016-12-01 02:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- public int getX() {
|
2018-07-22 22:46:13 +00:00
|
|
|
- return this.a;
|
|
|
|
+ // Paper start
|
2016-12-01 02:57:02 +00:00
|
|
|
+ public final int getX() {
|
2018-07-22 22:46:13 +00:00
|
|
|
+ return this.x;
|
2016-12-01 02:57:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-22 22:46:13 +00:00
|
|
|
public int getY() {
|
|
|
|
- return this.b;
|
|
|
|
+ return this.y;
|
2016-12-01 02:57:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-22 22:46:13 +00:00
|
|
|
public int getZ() {
|
|
|
|
- return this.c;
|
|
|
|
+ return this.z;
|
2016-12-01 02:57:02 +00:00
|
|
|
}
|
|
|
|
+ // Paper end
|
|
|
|
|
2019-01-01 03:15:55 +00:00
|
|
|
public BaseBlockPosition d(BaseBlockPosition baseblockposition) {
|
|
|
|
return new BaseBlockPosition(this.getY() * baseblockposition.getZ() - this.getZ() * baseblockposition.getY(), this.getZ() * baseblockposition.getX() - this.getX() * baseblockposition.getZ(), this.getX() * baseblockposition.getY() - this.getY() * baseblockposition.getX());
|
2019-04-30 01:20:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a(BaseBlockPosition baseblockposition, double d0) {
|
|
|
|
- return this.distanceSquared((double) baseblockposition.a, (double) baseblockposition.b, (double) baseblockposition.c, false) < d0 * d0;
|
|
|
|
+ return this.distanceSquared((double) baseblockposition.x, (double) baseblockposition.y, (double) baseblockposition.z, false) < d0 * d0; // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a(IPosition iposition, double d0) {
|
|
|
|
@@ -91,9 +93,9 @@ public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
|
|
|
|
}
|
|
|
|
|
|
|
|
public int n(BaseBlockPosition baseblockposition) {
|
|
|
|
- float f = (float) Math.abs(baseblockposition.getX() - this.a);
|
|
|
|
- float f1 = (float) Math.abs(baseblockposition.getY() - this.b);
|
|
|
|
- float f2 = (float) Math.abs(baseblockposition.getZ() - this.c);
|
|
|
|
+ float f = (float) Math.abs(baseblockposition.getX() - this.x); // Paper
|
|
|
|
+ float f1 = (float) Math.abs(baseblockposition.getY() - this.y); // Paper
|
|
|
|
+ float f2 = (float) Math.abs(baseblockposition.getZ() - this.z); // Paper
|
|
|
|
|
|
|
|
return (int) (f + f1 + f2);
|
|
|
|
}
|
2016-12-01 02:57:02 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/BlockPosition.java b/src/main/java/net/minecraft/server/BlockPosition.java
|
2019-05-14 21:54:32 +00:00
|
|
|
index 64700b97c0..a5e5a4ebae 100644
|
2016-12-01 02:57:02 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/BlockPosition.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/BlockPosition.java
|
2019-04-30 01:20:24 +00:00
|
|
|
@@ -335,11 +335,12 @@ public class BlockPosition extends BaseBlockPosition implements MinecraftSeriali
|
2019-01-01 03:15:55 +00:00
|
|
|
}
|
2016-12-01 02:57:02 +00:00
|
|
|
|
|
|
|
public static class MutableBlockPosition extends BlockPosition {
|
2019-01-01 03:15:55 +00:00
|
|
|
-
|
2018-07-22 22:46:13 +00:00
|
|
|
+ // Paper start - comment out
|
2016-12-01 02:57:02 +00:00
|
|
|
+ /*
|
|
|
|
protected int b;
|
|
|
|
protected int c;
|
|
|
|
protected int d;
|
2018-07-22 22:46:13 +00:00
|
|
|
- // Paper start
|
|
|
|
+
|
|
|
|
@Override
|
|
|
|
public boolean isValidLocation() {
|
|
|
|
return b >= -30000000 && d >= -30000000 && b < 30000000 && d < 30000000 && c >= 0 && c < 256;
|
2019-04-30 01:20:24 +00:00
|
|
|
@@ -348,6 +349,7 @@ public class BlockPosition extends BaseBlockPosition implements MinecraftSeriali
|
2016-12-01 02:57:02 +00:00
|
|
|
public boolean isInvalidYLocation() {
|
|
|
|
return c < 0 || c >= 256;
|
|
|
|
}
|
|
|
|
+ */
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
public MutableBlockPosition() {
|
2019-04-30 01:20:24 +00:00
|
|
|
@@ -359,10 +361,13 @@ public class BlockPosition extends BaseBlockPosition implements MinecraftSeriali
|
2018-07-22 22:46:13 +00:00
|
|
|
}
|
2016-12-01 02:57:02 +00:00
|
|
|
|
|
|
|
public MutableBlockPosition(int i, int j, int k) {
|
2018-07-22 22:46:13 +00:00
|
|
|
- super(0, 0, 0);
|
|
|
|
+ // Paper start
|
|
|
|
+ super(i, j, k);
|
|
|
|
+ /*
|
|
|
|
this.b = i;
|
|
|
|
this.c = j;
|
2016-12-01 02:57:02 +00:00
|
|
|
- this.d = k;
|
2018-07-22 22:46:13 +00:00
|
|
|
+ this.d = k;*/
|
2016-12-01 02:57:02 +00:00
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
2019-04-30 01:20:24 +00:00
|
|
|
public MutableBlockPosition(double d0, double d1, double d2) {
|
|
|
|
@@ -389,6 +394,9 @@ public class BlockPosition extends BaseBlockPosition implements MinecraftSeriali
|
|
|
|
return super.a(enumblockrotation).immutableCopy();
|
2016-12-01 02:57:02 +00:00
|
|
|
}
|
|
|
|
|
2019-04-30 01:20:24 +00:00
|
|
|
+
|
2016-12-01 02:57:02 +00:00
|
|
|
+ /*
|
2018-07-22 22:46:13 +00:00
|
|
|
+ // Paper start - use parent getters
|
2019-04-30 01:20:24 +00:00
|
|
|
@Override
|
2016-12-01 02:57:02 +00:00
|
|
|
public int getX() {
|
|
|
|
return this.b;
|
2019-04-30 01:20:24 +00:00
|
|
|
@@ -402,13 +410,16 @@ public class BlockPosition extends BaseBlockPosition implements MinecraftSeriali
|
|
|
|
@Override
|
2016-12-01 02:57:02 +00:00
|
|
|
public int getZ() {
|
|
|
|
return this.d;
|
2018-07-22 22:46:13 +00:00
|
|
|
- }
|
|
|
|
+ }*/
|
2016-12-01 02:57:02 +00:00
|
|
|
+ // Paper end
|
|
|
|
|
2019-04-30 01:20:24 +00:00
|
|
|
public BlockPosition.MutableBlockPosition setValues(int i, int j, int k) { return d(i, j, k);} // Paper - OBFHELPER
|
|
|
|
public BlockPosition.MutableBlockPosition d(int i, int j, int k) {
|
2016-12-01 02:57:02 +00:00
|
|
|
- this.b = i;
|
|
|
|
- this.c = j;
|
|
|
|
- this.d = k;
|
2018-07-22 22:46:13 +00:00
|
|
|
+ // Paper start - use xyz
|
|
|
|
+ this.x = i;
|
|
|
|
+ this.y = j;
|
|
|
|
+ this.z = k;
|
2016-12-01 02:57:02 +00:00
|
|
|
+ // Paper end
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-04-30 01:20:24 +00:00
|
|
|
@@ -438,15 +449,15 @@ public class BlockPosition extends BaseBlockPosition implements MinecraftSeriali
|
2016-12-01 02:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public BlockPosition.MutableBlockPosition c(EnumDirection enumdirection, int i) {
|
2019-04-30 01:20:24 +00:00
|
|
|
- return this.d(this.b + enumdirection.getAdjacentX() * i, this.c + enumdirection.getAdjacentY() * i, this.d + enumdirection.getAdjacentZ() * i);
|
|
|
|
+ return this.d(this.x + enumdirection.getAdjacentX() * i, this.y + enumdirection.getAdjacentY() * i, this.z + enumdirection.getAdjacentZ() * i);
|
2018-07-22 22:46:13 +00:00
|
|
|
}
|
|
|
|
|
2019-04-30 01:20:24 +00:00
|
|
|
public BlockPosition.MutableBlockPosition e(int i, int j, int k) {
|
|
|
|
- return this.d(this.b + i, this.c + j, this.d + k);
|
|
|
|
+ return this.d(this.x + i, this.y + j, this.z + k);
|
2016-12-01 02:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void p(int i) {
|
|
|
|
- this.c = i;
|
2018-07-22 22:46:13 +00:00
|
|
|
+ this.y = i; // Paper change to y
|
2016-12-01 02:57:02 +00:00
|
|
|
}
|
|
|
|
|
2019-04-30 01:20:24 +00:00
|
|
|
@Override
|
2016-12-01 02:57:02 +00:00
|
|
|
--
|
2019-03-20 01:46:00 +00:00
|
|
|
2.21.0
|
2016-12-01 02:57:02 +00:00
|
|
|
|