2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Techcable <Techcable@outlook.com>
|
|
|
|
Date: Wed, 30 Nov 2016 20:56:58 -0600
|
|
|
|
Subject: [PATCH] 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.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/core/Vec3i.java b/src/main/java/net/minecraft/core/Vec3i.java
|
2024-01-23 15:43:48 +01:00
|
|
|
index 1b29c6872ebe54351f28c1f1f38b22561ba785ee..5256ff18d992250e04a6180e196c2d5d3f0928ca 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/core/Vec3i.java
|
|
|
|
+++ b/src/main/java/net/minecraft/core/Vec3i.java
|
2024-01-23 15:43:48 +01:00
|
|
|
@@ -38,7 +38,7 @@ public class Vec3i implements Comparable<Vec3i> {
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
2021-06-12 23:31:35 +02:00
|
|
|
@Override
|
2021-06-11 14:02:28 +02:00
|
|
|
- public boolean equals(Object object) {
|
2024-01-21 19:37:09 +01:00
|
|
|
+ public final boolean equals(Object object) { // Paper - Perf: Final for inline
|
2021-06-11 14:02:28 +02:00
|
|
|
if (this == object) {
|
|
|
|
return true;
|
|
|
|
} else if (!(object instanceof Vec3i)) {
|
2024-01-23 15:43:48 +01:00
|
|
|
@@ -56,7 +56,7 @@ public class Vec3i implements Comparable<Vec3i> {
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
2021-06-12 23:31:35 +02:00
|
|
|
@Override
|
2021-06-11 14:02:28 +02:00
|
|
|
- public int hashCode() {
|
2024-01-21 19:37:09 +01:00
|
|
|
+ public final int hashCode() { // Paper - Perf: Final for inline
|
2021-06-11 14:02:28 +02:00
|
|
|
return (this.getY() + this.getZ() * 31) * 31 + this.getX();
|
|
|
|
}
|
|
|
|
|
2024-01-23 15:43:48 +01:00
|
|
|
@@ -69,15 +69,15 @@ public class Vec3i implements Comparable<Vec3i> {
|
2021-06-12 23:31:35 +02:00
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- public int getX() {
|
2024-01-21 19:37:09 +01:00
|
|
|
+ public final int getX() { // Paper - Perf: Final for inline
|
2021-06-11 14:02:28 +02:00
|
|
|
return this.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
- public int getY() {
|
2024-01-21 19:37:09 +01:00
|
|
|
+ public final int getY() { // Paper - Perf: Final for inline
|
2021-06-11 14:02:28 +02:00
|
|
|
return this.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
- public int getZ() {
|
2024-01-21 19:37:09 +01:00
|
|
|
+ public final int getZ() { // Paper - Perf: Final for inline
|
2021-06-11 14:02:28 +02:00
|
|
|
return this.z;
|
|
|
|
}
|
|
|
|
|