mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-23 09:27:45 +01:00
Reduce MutableInt and Vec3d allocations, use ArrayDeque
This commit is contained in:
parent
84673141a0
commit
511b6bc278
@ -5,7 +5,7 @@ Subject: [PATCH] ChunkMapDistance CME
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/ChunkMapDistance.java b/src/main/java/net/minecraft/server/ChunkMapDistance.java
|
||||
index ae661297774f51c8b61fc08ca43e13ba368d0021..0244768f76d83af427a07bd235c9bcec8ad5429e 100644
|
||||
index ae661297774f51c8b61fc08ca43e13ba368d0021..682a64c775adc1254f12d9f93b23375735ed4895 100644
|
||||
--- a/src/main/java/net/minecraft/server/ChunkMapDistance.java
|
||||
+++ b/src/main/java/net/minecraft/server/ChunkMapDistance.java
|
||||
@@ -33,7 +33,7 @@ public abstract class ChunkMapDistance {
|
||||
@ -13,7 +13,7 @@ index ae661297774f51c8b61fc08ca43e13ba368d0021..0244768f76d83af427a07bd235c9bcec
|
||||
private final ChunkMapDistance.b f = new ChunkMapDistance.b(8);
|
||||
private final ChunkMapDistance.c g = new ChunkMapDistance.c(33);
|
||||
- private final Set<PlayerChunk> pendingChunkUpdates = Sets.newHashSet();
|
||||
+ private final java.util.Queue<PlayerChunk> pendingChunkUpdates = new java.util.LinkedList<>(); // PAIL pendingChunkUpdates // Paper - use a queue
|
||||
+ private final java.util.Queue<PlayerChunk> pendingChunkUpdates = new java.util.ArrayDeque<>(); // PAIL pendingChunkUpdates // Paper - use a queue
|
||||
private final ChunkTaskQueueSorter i;
|
||||
private final Mailbox<ChunkTaskQueueSorter.a<Runnable>> j;
|
||||
private final Mailbox<ChunkTaskQueueSorter.b> k;
|
||||
|
@ -6,7 +6,7 @@ Subject: [PATCH] Optimize isOutsideRange to use distance maps
|
||||
Use a distance map to find the players in range quickly
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/ChunkMapDistance.java b/src/main/java/net/minecraft/server/ChunkMapDistance.java
|
||||
index 279c7a85fb5b4bff91fba1c9797c902bd68d8539..7cd4e2912351eae35b46dba1c8a471af781dc98b 100644
|
||||
index 534bb87caf88f0f1bf7988494274b762ab7210e1..b98abed74f214932b4a226f12645f987191b0097 100644
|
||||
--- a/src/main/java/net/minecraft/server/ChunkMapDistance.java
|
||||
+++ b/src/main/java/net/minecraft/server/ChunkMapDistance.java
|
||||
@@ -31,7 +31,7 @@ public abstract class ChunkMapDistance {
|
||||
@ -16,7 +16,7 @@ index 279c7a85fb5b4bff91fba1c9797c902bd68d8539..7cd4e2912351eae35b46dba1c8a471af
|
||||
- private final ChunkMapDistance.b f = new ChunkMapDistance.b(8);
|
||||
+ public static final int MOB_SPAWN_RANGE = 8; //private final ChunkMapDistance.b f = new ChunkMapDistance.b(8); // Paper - no longer used
|
||||
private final ChunkMapDistance.c g = new ChunkMapDistance.c(33);
|
||||
private final java.util.Queue<PlayerChunk> pendingChunkUpdates = new java.util.LinkedList<>(); // PAIL pendingChunkUpdates // Paper - use a queue
|
||||
private final java.util.Queue<PlayerChunk> pendingChunkUpdates = new java.util.ArrayDeque<>(); // PAIL pendingChunkUpdates // Paper - use a queue
|
||||
private final ChunkTaskQueueSorter i;
|
||||
@@ -41,6 +41,8 @@ public abstract class ChunkMapDistance {
|
||||
private final Executor m;
|
||||
@ -148,7 +148,7 @@ index 99be314307071e7b85ba444dcab923dd4edf0ddb..8ca6adbac2d2e43bf597c405134c1c5c
|
||||
this.world.timings.mobSpawn.startTiming(); // Spigot
|
||||
EnumCreatureType[] aenumcreaturetype1 = aenumcreaturetype;
|
||||
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
|
||||
index 48bbaec4b64bede8d280bd866436f5528578013e..6e8179b4651fca214b8957992ec6c9438c0da799 100644
|
||||
index 79c2187b7383336e7574709e6d4ad805e557976f..0560eca744cb2032bb6a3faf5aeafa95a7a6815e 100644
|
||||
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
|
||||
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
|
||||
@@ -109,6 +109,8 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
||||
|
@ -0,0 +1,60 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Spottedleaf <spottedleaf@spottedleaf.dev>
|
||||
Date: Mon, 27 Apr 2020 02:48:06 -0700
|
||||
Subject: [PATCH] Reduce MutableInt allocations from light engine
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/LightEngineBlock.java b/src/main/java/net/minecraft/server/LightEngineBlock.java
|
||||
index 93a972605c26aa757b9c915876f847da04fcb496..c4ba30bd56e2ead6015c0109f8e889388afeb7f2 100644
|
||||
--- a/src/main/java/net/minecraft/server/LightEngineBlock.java
|
||||
+++ b/src/main/java/net/minecraft/server/LightEngineBlock.java
|
||||
@@ -37,7 +37,10 @@ public final class LightEngineBlock extends LightEngineLayer<LightEngineStorageB
|
||||
if (enumdirection == null) {
|
||||
return 15;
|
||||
} else {
|
||||
- MutableInt mutableint = new MutableInt();
|
||||
+ // Paper start - reduce mutableint allocations
|
||||
+ MutableInt mutableint = com.destroystokyo.paper.util.pooled.PooledObjects.POOLED_MUTABLE_INTEGERS.acquire();
|
||||
+ try {
|
||||
+ // Paper end - reduce mutableint allocations
|
||||
IBlockData iblockdata = this.a(j, mutableint);
|
||||
|
||||
if (mutableint.getValue() >= 15) {
|
||||
@@ -49,6 +52,10 @@ public final class LightEngineBlock extends LightEngineLayer<LightEngineStorageB
|
||||
|
||||
return VoxelShapes.b(voxelshape, voxelshape1) ? 15 : k + Math.max(1, mutableint.getValue());
|
||||
}
|
||||
+ } finally { // Paper start - reduce mutableint allocations
|
||||
+ com.destroystokyo.paper.util.pooled.PooledObjects.POOLED_MUTABLE_INTEGERS.release(mutableint);
|
||||
+ }
|
||||
+ // Paper end - reduce mutableint allocations
|
||||
}
|
||||
}
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/server/LightEngineSky.java b/src/main/java/net/minecraft/server/LightEngineSky.java
|
||||
index 2301a982e17ab9568e3da9ca84c4a024c7c1b214..0b4f4604f4ea444017c021768574646a8d11ba26 100644
|
||||
--- a/src/main/java/net/minecraft/server/LightEngineSky.java
|
||||
+++ b/src/main/java/net/minecraft/server/LightEngineSky.java
|
||||
@@ -27,7 +27,10 @@ public final class LightEngineSky extends LightEngineLayer<LightEngineStorageSky
|
||||
if (k >= 15) {
|
||||
return k;
|
||||
} else {
|
||||
- MutableInt mutableint = new MutableInt();
|
||||
+ // Paper start - reduce mutableint allocations
|
||||
+ MutableInt mutableint = com.destroystokyo.paper.util.pooled.PooledObjects.POOLED_MUTABLE_INTEGERS.acquire();
|
||||
+ try {
|
||||
+ // Paper end - reduce mutableint allocations
|
||||
IBlockData iblockdata = this.a(j, mutableint);
|
||||
|
||||
if (mutableint.getValue() >= 15) {
|
||||
@@ -85,6 +88,10 @@ public final class LightEngineSky extends LightEngineLayer<LightEngineStorageSky
|
||||
|
||||
return flag1 && k == 0 && mutableint.getValue() == 0 ? 0 : k + Math.max(1, mutableint.getValue());
|
||||
}
|
||||
+ } finally { // Paper start - reduce mutableint allocations
|
||||
+ com.destroystokyo.paper.util.pooled.PooledObjects.POOLED_MUTABLE_INTEGERS.release(mutableint);
|
||||
+ }
|
||||
+ // Paper end - reduce mutableint allocations
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Spottedleaf <spottedleaf@spottedleaf.dev>
|
||||
Date: Mon, 27 Apr 2020 00:04:16 -0700
|
||||
Subject: [PATCH] Reduce allocation of Vec3D by entity tracker
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/EntityTrackerEntry.java b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
|
||||
index 6d3b34ead9cc95dcc1152dffa8c6c4a8c7f1d58b..5cc89c0cf9e9e632212a9653391437cbe9b15031 100644
|
||||
--- a/src/main/java/net/minecraft/server/EntityTrackerEntry.java
|
||||
+++ b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
|
||||
@@ -125,8 +125,12 @@ public class EntityTrackerEntry {
|
||||
++this.o;
|
||||
i = MathHelper.d(this.tracker.yaw * 256.0F / 360.0F);
|
||||
j = MathHelper.d(this.tracker.pitch * 256.0F / 360.0F);
|
||||
- Vec3D vec3d = this.tracker.getPositionVector().d(PacketPlayOutEntity.a(this.xLoc, this.yLoc, this.zLoc));
|
||||
- boolean flag1 = vec3d.g() >= 7.62939453125E-6D;
|
||||
+ // Paper start - reduce allocation of Vec3D here
|
||||
+ double vec3d_dx = this.tracker.locX() - 2.44140625E-4D*(this.xLoc);
|
||||
+ double vec3d_dy = this.tracker.locY() - 2.44140625E-4D*(this.yLoc);
|
||||
+ double vec3d_dz = this.tracker.locZ() - 2.44140625E-4D*(this.zLoc);
|
||||
+ boolean flag1 = (vec3d_dx * vec3d_dx + vec3d_dy * vec3d_dy + vec3d_dz * vec3d_dz) >= 7.62939453125E-6D;
|
||||
+ // Paper end - reduce allocation of Vec3D here
|
||||
Packet<?> packet1 = null;
|
||||
boolean flag2 = flag1 || this.tickCounter % 60 == 0;
|
||||
boolean flag3 = Math.abs(i - this.yRot) >= 1 || Math.abs(j - this.xRot) >= 1;
|
||||
@@ -143,9 +147,11 @@ public class EntityTrackerEntry {
|
||||
// CraftBukkit end
|
||||
|
||||
if (this.tickCounter > 0 || this.tracker instanceof EntityArrow) {
|
||||
- long k = PacketPlayOutEntity.a(vec3d.x);
|
||||
- long l = PacketPlayOutEntity.a(vec3d.y);
|
||||
- long i1 = PacketPlayOutEntity.a(vec3d.z);
|
||||
+ // Paper start - remove allocation of Vec3D here
|
||||
+ long k = PacketPlayOutEntity.a(vec3d_dx);
|
||||
+ long l = PacketPlayOutEntity.a(vec3d_dy);
|
||||
+ long i1 = PacketPlayOutEntity.a(vec3d_dz);
|
||||
+ // Paper end - remove allocation of Vec3D here
|
||||
boolean flag4 = k < -32768L || k > 32767L || l < -32768L || l > 32767L || i1 < -32768L || i1 > 32767L;
|
||||
|
||||
if (!flag4 && this.o <= 400 && !this.q && this.r == this.tracker.onGround) {
|
||||
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
||||
index 81bb26abc520f49de2e916cf2757ac4c710d02cd..263cc1e0a476797a73c37724326feec37f114ecf 100644
|
||||
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
||||
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
||||
@@ -2130,9 +2130,14 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
|
||||
public void updatePlayer(EntityPlayer entityplayer) {
|
||||
org.spigotmc.AsyncCatcher.catchOp("player tracker update"); // Spigot
|
||||
if (entityplayer != this.tracker) {
|
||||
- Vec3D vec3d = entityplayer.getPositionVector().d(this.tracker.getPositionVector()); // MC-155077, SPIGOT-5113
|
||||
+ // Paper start - remove allocation of Vec3D here
|
||||
+ //Vec3D vec3d = entityplayer.getPositionVector().d(this.tracker.getPositionVector()); // MC-155077, SPIGOT-5113
|
||||
+ double vec3d_dx = entityplayer.locX() - this.tracker.locX();
|
||||
+ double vec3d_dy = entityplayer.locY() - this.tracker.locY();
|
||||
+ double vec3d_dz = entityplayer.locZ() - this.tracker.locZ();
|
||||
+ // Paper end - remove allocation of Vec3D here
|
||||
int i = Math.min(this.b(), (PlayerChunkMap.this.viewDistance - 1) * 16);
|
||||
- boolean flag = vec3d.x >= (double) (-i) && vec3d.x <= (double) i && vec3d.z >= (double) (-i) && vec3d.z <= (double) i && this.tracker.a(entityplayer);
|
||||
+ boolean flag = vec3d_dx >= (double) (-i) && vec3d_dx <= (double) i && vec3d_dz >= (double) (-i) && vec3d_dz <= (double) i && this.tracker.a(entityplayer); // Paper - remove allocation of Vec3D here
|
||||
|
||||
if (flag) {
|
||||
boolean flag1 = this.tracker.attachedToPlayer;
|
Loading…
Reference in New Issue
Block a user