Paper 1.9
This commit is contained in:
@@ -1,154 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Techcable <Techcable@outlook.com>
|
||||
Date: Fri, 29 Jan 2016 03:24:21 -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
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/BaseBlockPosition.java
|
||||
+++ b/src/main/java/net/minecraft/server/BaseBlockPosition.java
|
||||
@@ -0,0 +0,0 @@ import com.google.common.base.Objects;
|
||||
public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
|
||||
|
||||
public static final BaseBlockPosition ZERO = new BaseBlockPosition(0, 0, 0);
|
||||
- private final int a;
|
||||
- private final int c;
|
||||
- private final int d;
|
||||
+ // PaperSpigot start - Make mutable and protected for MutableBlockPos
|
||||
+ protected int a;
|
||||
+ protected int c;
|
||||
+ protected int d;
|
||||
+ // PaperSpigot end
|
||||
|
||||
public BaseBlockPosition(int i, int j, int k) {
|
||||
this.a = i;
|
||||
@@ -0,0 +0,0 @@ public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
|
||||
return this.getY() == baseblockposition.getY() ? (this.getZ() == baseblockposition.getZ() ? this.getX() - baseblockposition.getX() : this.getZ() - baseblockposition.getZ()) : this.getY() - baseblockposition.getY();
|
||||
}
|
||||
|
||||
- public int getX() {
|
||||
+ // PaperSpigot start - Only allow one implementation of these methods (make final)
|
||||
+ public final int getX() {
|
||||
return this.a;
|
||||
}
|
||||
|
||||
- public int getY() {
|
||||
+ public final int getY() {
|
||||
return this.c;
|
||||
}
|
||||
|
||||
- public int getZ() {
|
||||
+ public final int getZ() {
|
||||
return this.d;
|
||||
}
|
||||
+ // PaperSpigot end
|
||||
|
||||
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());
|
||||
@@ -0,0 +0,0 @@ public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
|
||||
return Objects.toStringHelper(this).add("x", this.getX()).add("y", this.getY()).add("z", this.getZ()).toString();
|
||||
}
|
||||
|
||||
- public int compareTo(Object object) {
|
||||
+ // Paperspigot - Signature change, Object -> BaseBlockPosition
|
||||
+ public int compareTo(BaseBlockPosition object) {
|
||||
return this.g((BaseBlockPosition) object);
|
||||
}
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/server/BlockPosition.java b/src/main/java/net/minecraft/server/BlockPosition.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/BlockPosition.java
|
||||
+++ b/src/main/java/net/minecraft/server/BlockPosition.java
|
||||
@@ -0,0 +0,0 @@ public class BlockPosition extends BaseBlockPosition {
|
||||
++k;
|
||||
}
|
||||
|
||||
- this.b.c = i;
|
||||
- this.b.d = j;
|
||||
- this.b.e = k;
|
||||
+ // PaperSpigot start
|
||||
+ this.b.setX(i);
|
||||
+ this.b.setY(j);
|
||||
+ this.b.setZ(k);
|
||||
+ // PaperSpigot stop
|
||||
return this.b;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +0,0 @@ public class BlockPosition extends BaseBlockPosition {
|
||||
|
||||
public static final class MutableBlockPosition extends BlockPosition {
|
||||
|
||||
+ // PaperSpigot start - remove our overriding variables
|
||||
+ /*
|
||||
private int c;
|
||||
private int d;
|
||||
private int e;
|
||||
+ */
|
||||
+
|
||||
+ public void setX(int x) {
|
||||
+ ((BaseBlockPosition) this).a = x;
|
||||
+ }
|
||||
+
|
||||
+ public void setY(int y) {
|
||||
+ ((BaseBlockPosition) this).c = y;
|
||||
+ }
|
||||
+
|
||||
+ public void setZ(int z) {
|
||||
+ ((BaseBlockPosition) this).d = z;
|
||||
+ }
|
||||
+ // PaperSpigot end
|
||||
|
||||
public MutableBlockPosition() {
|
||||
this(0, 0, 0);
|
||||
@@ -0,0 +0,0 @@ public class BlockPosition extends BaseBlockPosition {
|
||||
|
||||
public MutableBlockPosition(int i, int j, int k) {
|
||||
super(0, 0, 0);
|
||||
- this.c = i;
|
||||
- this.d = j;
|
||||
- this.e = k;
|
||||
+ // PaperSpigot start - modify base x,y,z
|
||||
+ this.setX(i);
|
||||
+ this.setY(j);
|
||||
+ this.setZ(k);
|
||||
}
|
||||
|
||||
+ /*
|
||||
public int getX() {
|
||||
return this.c;
|
||||
}
|
||||
@@ -0,0 +0,0 @@ public class BlockPosition extends BaseBlockPosition {
|
||||
public int getZ() {
|
||||
return this.e;
|
||||
}
|
||||
+ */
|
||||
|
||||
public BlockPosition.MutableBlockPosition c(int i, int j, int k) {
|
||||
- this.c = i;
|
||||
- this.d = j;
|
||||
- this.e = k;
|
||||
+ setX(i);
|
||||
+ setY(j);
|
||||
+ setZ(k);
|
||||
+ // PaperSpigot end
|
||||
return this;
|
||||
}
|
||||
|
||||
--
|
||||
Reference in New Issue
Block a user