forked from hpfxd/PandaSpigot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0013-Optimise-non-flush-packet-sending.patch
53 lines (46 loc) · 2.27 KB
/
0013-Optimise-non-flush-packet-sending.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <[email protected]>
Date: Fri, 29 Oct 2021 08:25:50 -0400
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/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java
index da76acafb5ffaea16f6a4dc28122c82f41bed318..ae7c6e289c8a6d9f8bdd4911e90e2ef9840069a2 100644
--- a/src/main/java/net/minecraft/server/NetworkManager.java
+++ b/src/main/java/net/minecraft/server/NetworkManager.java
@@ -304,8 +304,7 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet> {
}
// PandaSpigot end
} else {
- this.channel.eventLoop().execute(new Runnable() {
- public void run() {
+ Runnable command = () -> { // PandaSpigot - optimise packets that are not flushed
if (enumprotocol != enumprotocol1) {
NetworkManager.this.a(enumprotocol);
}
@@ -336,8 +335,15 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet> {
packet.onPacketDispatchFinish(player, null);
}
// PandaSpigot end
- }
- });
+ };
+ // PandaSpigot start - optimise packets that are not flushed
+ if (!flush) {
+ io.netty.util.concurrent.AbstractEventExecutor.LazyRunnable run = command::run;
+ this.channel.eventLoop().execute(run);
+ } else {
+ this.channel.eventLoop().execute(command);
+ }
+ // PandaSpigot end
}
}