-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-apply some dropped paper performance patches
- Loading branch information
Showing
16 changed files
with
154 additions
and
14 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
patches/server/0001-Reduce-allocation-of-Vec3D-by-entity-tracker.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Spottedleaf <[email protected]> | ||
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 | ||
index 33d9131e9c75ef23cd637f5d6c39a2704a0c92a5..4b6e0fe2fabcc55007fd8979e81f66df9c0278b7 100644 | ||
--- a/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java | ||
+++ b/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java | ||
@@ -5,7 +5,7 @@ import org.jetbrains.annotations.VisibleForTesting; | ||
|
||
public class VecDeltaCodec { | ||
private static final double TRUNCATION_STEPS = 4096.0D; | ||
- private Vec3 base = Vec3.ZERO; | ||
+ public Vec3 base = Vec3.ZERO; // Paper | ||
|
||
@VisibleForTesting | ||
static long encode(double value) { | ||
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java | ||
index caa73632aee15583c6b6ed12a668c8f49b794708..73d50715d34fdf67f346672901dd1d24bb2ac7fb 100644 | ||
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java | ||
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java | ||
@@ -1419,10 +1419,14 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider | ||
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()); | ||
+ // 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); | ||
- 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; | ||
boolean flag = d1 <= d2 && this.entity.broadcastToPlayer(player) && ChunkMap.this.isChunkTracked(player, this.entity.chunkPosition().x, this.entity.chunkPosition().z); | ||
// Paper start - check Y | ||
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java | ||
index 35674f92a67f93382103c2766df4b678ba5c862f..fd75d4b04ca560a3c1c0035052ff0073b7081d71 100644 | ||
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java | ||
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java | ||
@@ -164,7 +164,13 @@ public class ServerEntity { | ||
i = Mth.floor(this.entity.getYRot() * 256.0F / 360.0F); | ||
j = Mth.floor(this.entity.getXRot() * 256.0F / 360.0F); | ||
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 = Math.abs(i - this.yRotp) >= 1 || Math.abs(j - this.xRotp) >= 1; |
81 changes: 81 additions & 0 deletions
81
patches/server/0002-Optimize-non-flush-packet-sending.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Spottedleaf <[email protected]> | ||
Date: Tue, 22 Sep 2020 01:49:19 -0700 | ||
Subject: [PATCH] Optimize non-flush packet sending | ||
|
||
Places like entity tracking make heavy use of packet sending, | ||
and internally netty will use some very expensive thread wakeup | ||
calls when scheduling. | ||
|
||
Thanks to various hacks in ProtocolLib as well as other | ||
plugins, we cannot simply use a queue of packets to group | ||
send on execute. We have to call execute for each packet. | ||
|
||
Tux's suggestion here is exactly what was needed - tag | ||
the Runnable indicating it should not make a wakeup call. | ||
|
||
Big thanks to Tux for making this possible as I had given | ||
up on this optimisation before he came along. | ||
|
||
Locally this patch drops the entity tracker tick by a full 1.5x. | ||
|
||
(1.20.2 update) | ||
Netty broke this LazyRunnable system in some version - this now uses | ||
the internal safeExecute method for lazy-scheduling the packet-sending | ||
runnables on the event loop. | ||
|
||
Co-authored-by: booky10 <[email protected]> | ||
|
||
diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java | ||
index c0ea20dcee8bb293df96bc6ee019e50ad6b383fd..11805569eefe100c2f469431d77a0d5a80c53244 100644 | ||
--- a/src/main/java/net/minecraft/network/Connection.java | ||
+++ b/src/main/java/net/minecraft/network/Connection.java | ||
@@ -60,6 +60,21 @@ import org.slf4j.MarkerFactory; | ||
|
||
public class Connection extends SimpleChannelInboundHandler<Packet<?>> { | ||
|
||
+ // Paper start | ||
+ private static final java.lang.invoke.MethodHandle SAFE_EXECUTE; | ||
+ | ||
+ static { | ||
+ try { | ||
+ Class<?> abstractChannelHandlerContext = Class.forName("io.netty.channel.AbstractChannelHandlerContext"); | ||
+ SAFE_EXECUTE = java.lang.invoke.MethodHandles.privateLookupIn(abstractChannelHandlerContext, java.lang.invoke.MethodHandles.lookup()) | ||
+ .findStatic(abstractChannelHandlerContext, "safeExecute", | ||
+ java.lang.invoke.MethodType.methodType(boolean.class, io.netty.util.concurrent.EventExecutor.class, Runnable.class, io.netty.channel.ChannelPromise.class, Object.class, boolean.class)); | ||
+ } catch (ReflectiveOperationException exception) { | ||
+ throw new RuntimeException(exception); | ||
+ } | ||
+ } | ||
+ // Paper end | ||
+ | ||
private static final float AVERAGE_PACKETS_SMOOTHING = 0.75F; | ||
private static final Logger LOGGER = LogUtils.getLogger(); | ||
public static final Marker ROOT_MARKER = MarkerFactory.getMarker("NETWORK"); | ||
@@ -429,9 +444,24 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> { | ||
if (this.channel.eventLoop().inEventLoop()) { | ||
this.doSendPacket(packet, callbacks, flush); | ||
} else { | ||
- this.channel.eventLoop().execute(() -> { | ||
+ // Paper start - optimise packets that are not flushed | ||
+ Runnable run = () -> { | ||
this.doSendPacket(packet, callbacks, flush); | ||
- }); | ||
+ }; | ||
+ | ||
+ if (flush) { | ||
+ this.channel.eventLoop().execute(run); | ||
+ } else { | ||
+ // netty dropped support for LazyRunnable in some version, so | ||
+ // this now needs to use method handles for calling lazy execute | ||
+ try { | ||
+ SAFE_EXECUTE.invoke(this.channel.eventLoop(), run, | ||
+ this.channel.voidPromise(), null, true); | ||
+ } catch (Throwable throwable) { | ||
+ throw new RuntimeException(throwable); | ||
+ } | ||
+ } | ||
+ // Paper end | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.