From d29296a0a12ffd5e4744372fcb1902a87572c07a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=E1=BA=A7n=20Nguy=E1=BB=85n=20Ng=E1=BB=8Dc=20Quang?= <3d7777456@gmail.com> Date: Wed, 17 Jan 2024 15:51:47 +0700 Subject: [PATCH] add back optimise non-flush packet sending patch --- ...04-Optimise-non-flush-packet-sending.patch | 46 ---------------- ...48-Optimise-non-flush-packet-sending.patch | 55 +++++++++++++++++++ 2 files changed, 55 insertions(+), 46 deletions(-) delete mode 100644 patches/removed/1.20.2/0704-Optimise-non-flush-packet-sending.patch create mode 100644 patches/server/1048-Optimise-non-flush-packet-sending.patch diff --git a/patches/removed/1.20.2/0704-Optimise-non-flush-packet-sending.patch b/patches/removed/1.20.2/0704-Optimise-non-flush-packet-sending.patch deleted file mode 100644 index 702421e3eb3a..000000000000 --- a/patches/removed/1.20.2/0704-Optimise-non-flush-packet-sending.patch +++ /dev/null @@ -1,46 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Spottedleaf -Date: Tue, 22 Sep 2020 01:49:19 -0700 -Subject: [PATCH] Optimise 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. - -diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java -index 9a9924a645c71e0cec30e29a9defcd1e22e2e8ef..15798ed13488b8b8b16ebee557dce18e3dc51708 100644 ---- a/src/main/java/net/minecraft/network/Connection.java -+++ b/src/main/java/net/minecraft/network/Connection.java -@@ -437,9 +437,19 @@ public class Connection extends SimpleChannelInboundHandler> { - if (this.channel.eventLoop().inEventLoop()) { - this.doSendPacket(packet, callbacks, enumprotocol, enumprotocol1, flush); // Paper - } else { -+ // Paper start - optimise packets that are not flushed -+ // note: since the type is not dynamic here, we need to actually copy the old executor code -+ // into two branches. On conflict, just re-copy - no changes were made inside the executor code. -+ if (!flush) { -+ io.netty.util.concurrent.AbstractEventExecutor.LazyRunnable run = () -> { -+ this.doSendPacket(packet, callbacks, enumprotocol, enumprotocol1, flush); // Paper - add flush parameter -+ }; -+ this.channel.eventLoop().execute(run); -+ } else { // Paper end - optimise packets that are not flushed - this.channel.eventLoop().execute(() -> { -- this.doSendPacket(packet, callbacks, enumprotocol, enumprotocol1, flush); // Paper -+ this.doSendPacket(packet, callbacks, enumprotocol, enumprotocol1, flush); // Paper - add flush parameter // Paper - diff on change - }); -+ } // Paper - } - - } diff --git a/patches/server/1048-Optimise-non-flush-packet-sending.patch b/patches/server/1048-Optimise-non-flush-packet-sending.patch new file mode 100644 index 000000000000..b00983f28dc7 --- /dev/null +++ b/patches/server/1048-Optimise-non-flush-packet-sending.patch @@ -0,0 +1,55 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Spottedleaf +Date: Tue, 22 Sep 2020 01:49:19 -0700 +Subject: [PATCH] Optimise 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. + +Co-authored-by: Quang Tran <3d7777456@gmail.com> + +diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java +index 2ae08b21c63490bbf8cd870f9585d82ed131f815..49fe7e623e4815232781ece9d0c2aff396676e1e 100644 +--- a/src/main/java/net/minecraft/network/Connection.java ++++ b/src/main/java/net/minecraft/network/Connection.java +@@ -148,6 +148,7 @@ public class Connection extends SimpleChannelInboundHandler> { + this.stopReadingPackets = true; + } + // Paper end - packet limiter ++ private io.netty.channel.SingleThreadEventLoop eventLoop; // Paper - optimise packets that are not flushed + + public Connection(PacketFlow side) { + this.receiving = side; +@@ -156,6 +157,7 @@ public class Connection extends SimpleChannelInboundHandler> { + public void channelActive(ChannelHandlerContext channelhandlercontext) throws Exception { + super.channelActive(channelhandlercontext); + this.channel = channelhandlercontext.channel(); ++ this.eventLoop = (io.netty.channel.SingleThreadEventLoop) this.channel.eventLoop(); // Paper - optimise packets that are not flushed + this.address = this.channel.remoteAddress(); + // Spigot Start + this.preparing = false; +@@ -429,6 +431,11 @@ public class Connection extends SimpleChannelInboundHandler> { + if (this.channel.eventLoop().inEventLoop()) { + this.doSendPacket(packet, callbacks, flush); + } else { ++ // Paper start - optimise packets that are not flushed ++ if (!flush) { ++ this.eventLoop.lazyExecute(() -> this.doSendPacket(packet, callbacks, flush)); ++ } else ++ // Paper end - optimise packets that are not flushed + this.channel.eventLoop().execute(() -> { + this.doSendPacket(packet, callbacks, flush); + });