mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-31 12:41:25 +01:00
Improve BlockPosition 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 microbenchmarks. They had 'callq' (invoke) instead of 'mov' (get from memory) instructions.
This commit is contained in:
parent
925d397466
commit
85be8cc620
@ -0,0 +1,36 @@
|
||||
--- a/net/minecraft/core/Vec3i.java
|
||||
+++ b/net/minecraft/core/Vec3i.java
|
||||
@@ -35,12 +35,12 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
- public boolean equals(Object object) {
|
||||
+ public final boolean equals(Object object) { // Paper - Perf: Final for inline
|
||||
return this == object || object instanceof Vec3i vec3i && this.getX() == vec3i.getX() && this.getY() == vec3i.getY() && this.getZ() == vec3i.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
- public int hashCode() {
|
||||
+ public final int hashCode() { // Paper - Perf: Final for inline
|
||||
return (this.getY() + this.getZ() * 31) * 31 + this.getX();
|
||||
}
|
||||
|
||||
@@ -53,15 +53,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
- public int getX() {
|
||||
+ public final int getX() { // Paper - Perf: Final for inline
|
||||
return this.x;
|
||||
}
|
||||
|
||||
- public int getY() {
|
||||
+ public final int getY() { // Paper - Perf: Final for inline
|
||||
return this.y;
|
||||
}
|
||||
|
||||
- public int getZ() {
|
||||
+ public final int getZ() { // Paper - Perf: Final for inline
|
||||
return this.z;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user