3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-14 20:10:05 +01:00
Paper/patches/server/0914-Reduce-allocation-of-Vec3D-by-entity-tracker.patch

60 Zeilen
3.6 KiB
Diff

2022-06-08 07:02:19 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
Rewrite chunk system (#8177) Patch documentation to come Issues with the old system that are fixed now: - World generation does not scale with cpu cores effectively. - Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps. - Unreliable prioritisation of chunk gen/load calls that block the main thread. - Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved. - Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal. - Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles. The above list is not complete. The patch documentation will complete it. New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil. Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft. The old legacy chunk system patches have been moved to the removed folder in case we need them again.
2022-09-26 10:02:51 +02:00
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
2022-06-08 07:02:19 +02:00
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/network/protocol/game/VecDeltaCodec.java b/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java
2024-06-14 10:56:28 +02:00
index a043ac10834562d357ef0b5aded2e916e2a0d056..74276c368016fcc4dbf9579b2ecbadc9614baf15 100644
--- a/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java
+++ b/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java
2022-12-07 21:16:54 +01:00
@@ -5,7 +5,7 @@ import org.jetbrains.annotations.VisibleForTesting;
public class VecDeltaCodec {
private static final double TRUNCATION_STEPS = 4096.0;
- private Vec3 base = Vec3.ZERO;
+ public Vec3 base = Vec3.ZERO; // Paper
2022-12-07 21:16:54 +01:00
@VisibleForTesting
static long encode(double value) {
2022-06-08 07:02:19 +02:00
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
2024-10-29 16:54:40 +01:00
index 7483f9f2639c58a4f43e264211791f4377e1db64..7317c353edab8b11d9d94e257f968ac49284f47a 100644
2022-06-08 07:02:19 +02:00
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
2024-10-27 18:11:15 +01:00
@@ -1572,10 +1572,14 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2022-06-08 07:02:19 +02:00
public void updatePlayer(ServerPlayer player) {
org.spigotmc.AsyncCatcher.catchOp("player tracker update"); // Spigot
if (player != this.entity) {
- Vec3 vec3d = player.position().subtract(this.entity.position());
2022-06-08 07:02:19 +02:00
+ // Paper start - remove allocation of Vec3D here
+ // Vec3 vec3d = player.position().subtract(this.entity.position());
+ double vec3d_dx = player.getX() - this.entity.getX();
+ double vec3d_dz = player.getZ() - this.entity.getZ();
+ // Paper end - remove allocation of Vec3D here
int i = ChunkMap.this.getPlayerViewDistance(player);
double d0 = (double) Math.min(this.getEffectiveRange(), i * 16);
2022-06-08 07:02:19 +02:00
- double d1 = vec3d.x * vec3d.x + vec3d.z * vec3d.z;
+ double d1 = vec3d_dx * vec3d_dx + vec3d_dz * vec3d_dz; // Paper
double d2 = d0 * d0;
// Paper start - Configurable entity tracking range by Y
boolean flag = d1 <= d2;
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
2024-10-24 15:25:36 +02:00
index 7118e1f806af98159ec292f9340d7e4004e2b486..f3456aeeab7eee5b6d0383a4bf1338dd8cc95bb3 100644
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
2024-10-24 15:25:36 +02:00
@@ -178,7 +178,13 @@ public class ServerEntity {
++this.teleportDelay;
Vec3 vec3d = this.entity.trackingPosition();
- boolean flag1 = this.positionCodec.delta(vec3d).lengthSqr() >= 7.62939453125E-6D;
+ // Paper start - reduce allocation of Vec3D here
+ Vec3 base = this.positionCodec.base;
+ double vec3d_dx = vec3d.x - base.x;
+ double vec3d_dy = vec3d.y - base.y;
+ double vec3d_dz = vec3d.z - base.z;
+ 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.tickCount % 60 == 0;
boolean flag3 = false;