aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0709-Optimise-non-flush-packet-sending.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/server/0709-Optimise-non-flush-packet-sending.patch')
-rw-r--r--patches/server/0709-Optimise-non-flush-packet-sending.patch46
1 files changed, 46 insertions, 0 deletions
diff --git a/patches/server/0709-Optimise-non-flush-packet-sending.patch b/patches/server/0709-Optimise-non-flush-packet-sending.patch
new file mode 100644
index 0000000000..fdc4b312bf
--- /dev/null
+++ b/patches/server/0709-Optimise-non-flush-packet-sending.patch
@@ -0,0 +1,46 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Spottedleaf <[email protected]>
+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 1690626b8a62e078ce23e725c0384983af9c9e23..bff8267b72f5e4a0530055ee58add657fa553dcd 100644
+--- a/src/main/java/net/minecraft/network/Connection.java
++++ b/src/main/java/net/minecraft/network/Connection.java
+@@ -428,9 +428,19 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
+ 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
+ }
+
+ }