-
Notifications
You must be signed in to change notification settings - Fork 110
/
0006-Optimize-entity-coordinate-key.patch
38 lines (34 loc) · 2.07 KB
/
0006-Optimize-entity-coordinate-key.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kevin Raneri <kevin.raneri@gmail.com>
Date: Tue, 9 Nov 2021 14:33:16 -0500
Subject: [PATCH] Optimize entity coordinate key
When executing getCoordinateKey for entities (a hotpath), the JVM is
required to repeatedly cast doubles to longs. The performance impact of
this depends on the CPU architecture, but generally switching between
FPU and ALU incurs a significant performance hit. The casted/rounded
data is already available in the blockPosition struct, so we use that
instead of re-doing the casting.
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
index b5be0486d1cffe60808948b4b0bfd709664b2ae4..32ed9432998764c20147d6060314a2da0784d7f8 100644
--- a/src/main/java/net/minecraft/server/MCUtil.java
+++ b/src/main/java/net/minecraft/server/MCUtil.java
@@ -203,7 +203,7 @@ public final class MCUtil {
}
public static long getCoordinateKey(final Entity entity) {
- return ((long)(MCUtil.fastFloor(entity.getZ()) >> 4) << 32) | ((MCUtil.fastFloor(entity.getX()) >> 4) & 0xFFFFFFFFL);
+ return ((long)(entity.blockPosition.getZ() >> 4) << 32) | ((entity.blockPosition.getX() >> 4) & 0xFFFFFFFFL); // Pufferfish - eliminate double->long cast in hotpath
}
public static long getCoordinateKey(final ChunkPos pair) {
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index aac9dd19237d0708990960d03328e7530cd7bc8e..cd7b868149390570dbb3455b7085998e25f218b3 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -223,7 +223,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
public double yo;
public double zo;
private Vec3 position;
- private BlockPos blockPosition;
+ public BlockPos blockPosition; // Pufferfish - private->public
private Vec3 deltaMovement;
public float yRot; // Paper - private->public
private float xRot;