forked from PaperMC/Waterfall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0051-Speed-up-packet-construction.patch
367 lines (355 loc) · 18.2 KB
/
0051-Speed-up-packet-construction.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
From dc148013708fe031509a9aa1592078bd0b59731f Mon Sep 17 00:00:00 2001
From: Mark Vainomaa <[email protected]>
Date: Wed, 17 Apr 2019 09:24:38 +0300
Subject: [PATCH] Speed up packet construction
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java
index 66c925d0..d372933d 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java
@@ -54,6 +54,7 @@ public enum Protocol
{
TO_SERVER.registerPacket(
Handshake.class,
+ Handshake::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x00 )
);
}
@@ -65,6 +66,7 @@ public enum Protocol
{
TO_CLIENT.registerPacket(
KeepAlive.class,
+ KeepAlive::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x00 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x1F ),
map( ProtocolConstants.MINECRAFT_1_13, 0x21 ),
@@ -75,6 +77,7 @@ public enum Protocol
);
TO_CLIENT.registerPacket(
Login.class,
+ Login::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x01 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x23 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x25 ),
@@ -84,6 +87,7 @@ public enum Protocol
);
TO_CLIENT.registerPacket(
Chat.class,
+ Chat::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x02 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x0F ),
map( ProtocolConstants.MINECRAFT_1_13, 0x0E ),
@@ -92,6 +96,7 @@ public enum Protocol
);
TO_CLIENT.registerPacket(
Respawn.class,
+ Respawn::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x07 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x33 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x34 ),
@@ -104,6 +109,7 @@ public enum Protocol
);
TO_CLIENT.registerPacket(
BossBar.class,
+ BossBar::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_9, 0x0C ),
map( ProtocolConstants.MINECRAFT_1_15, 0x0D ),
map( ProtocolConstants.MINECRAFT_1_16, 0x0C )
@@ -111,6 +117,7 @@ public enum Protocol
// Waterfall start
TO_CLIENT.registerPacket(
EntityEffect.class,
+ EntityEffect::new, // Waterfall - speed up packet construction
map(ProtocolConstants.MINECRAFT_1_8, 0x1D),
map(ProtocolConstants.MINECRAFT_1_9, 0x4C),
map(ProtocolConstants.MINECRAFT_1_9_4, 0x4B),
@@ -123,6 +130,7 @@ public enum Protocol
);
TO_CLIENT.registerPacket(
EntityRemoveEffect.class,
+ EntityRemoveEffect::new, // Waterfall - speed up packet construction
map(ProtocolConstants.MINECRAFT_1_8, 0x1E),
map(ProtocolConstants.MINECRAFT_1_9, 0x31),
map(ProtocolConstants.MINECRAFT_1_12, 0x32),
@@ -136,6 +144,7 @@ public enum Protocol
// Waterfall end
TO_CLIENT.registerPacket(
PlayerListItem.class, // PlayerInfo
+ PlayerListItem::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x38 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x2D ),
map( ProtocolConstants.MINECRAFT_1_12_1, 0x2E ),
@@ -147,6 +156,7 @@ public enum Protocol
);
TO_CLIENT.registerPacket(
TabCompleteResponse.class,
+ TabCompleteResponse::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x3A ),
map( ProtocolConstants.MINECRAFT_1_9, 0x0E ),
map( ProtocolConstants.MINECRAFT_1_13, 0x10 ),
@@ -156,6 +166,7 @@ public enum Protocol
);
TO_CLIENT.registerPacket(
ScoreboardObjective.class,
+ ScoreboardObjective::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x3B ),
map( ProtocolConstants.MINECRAFT_1_9, 0x3F ),
map( ProtocolConstants.MINECRAFT_1_12, 0x41 ),
@@ -166,6 +177,7 @@ public enum Protocol
);
TO_CLIENT.registerPacket(
ScoreboardScore.class,
+ ScoreboardScore::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x3C ),
map( ProtocolConstants.MINECRAFT_1_9, 0x42 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x44 ),
@@ -176,6 +188,7 @@ public enum Protocol
);
TO_CLIENT.registerPacket(
ScoreboardDisplay.class,
+ ScoreboardDisplay::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x3D ),
map( ProtocolConstants.MINECRAFT_1_9, 0x38 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x3A ),
@@ -186,6 +199,7 @@ public enum Protocol
);
TO_CLIENT.registerPacket(
Team.class,
+ Team::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x3E ),
map( ProtocolConstants.MINECRAFT_1_9, 0x41 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x43 ),
@@ -196,6 +210,7 @@ public enum Protocol
);
TO_CLIENT.registerPacket(
PluginMessage.class,
+ PluginMessage::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x3F ),
map( ProtocolConstants.MINECRAFT_1_9, 0x18 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x19 ),
@@ -206,6 +221,7 @@ public enum Protocol
);
TO_CLIENT.registerPacket(
Kick.class,
+ Kick::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x40 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x1A ),
map( ProtocolConstants.MINECRAFT_1_13, 0x1B ),
@@ -216,6 +232,7 @@ public enum Protocol
);
TO_CLIENT.registerPacket(
Title.class,
+ Title::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x45 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x47 ),
map( ProtocolConstants.MINECRAFT_1_12_1, 0x48 ),
@@ -226,6 +243,7 @@ public enum Protocol
);
TO_CLIENT.registerPacket(
PlayerListHeaderFooter.class,
+ PlayerListHeaderFooter::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x47 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x48 ),
map( ProtocolConstants.MINECRAFT_1_9_4, 0x47 ),
@@ -238,6 +256,7 @@ public enum Protocol
);
TO_CLIENT.registerPacket(
EntityStatus.class,
+ EntityStatus::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x1A ),
map( ProtocolConstants.MINECRAFT_1_9, 0x1B ),
map( ProtocolConstants.MINECRAFT_1_13, 0x1C ),
@@ -248,6 +267,7 @@ public enum Protocol
);
TO_CLIENT.registerPacket(
Commands.class,
+ Commands::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_13, 0x11 ),
map( ProtocolConstants.MINECRAFT_1_15, 0x12 ),
map( ProtocolConstants.MINECRAFT_1_16, 0x11 ),
@@ -255,12 +275,14 @@ public enum Protocol
);
TO_CLIENT.registerPacket(
GameState.class,
+ GameState::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_15, 0x1F ),
map( ProtocolConstants.MINECRAFT_1_16, 0x1E ),
map( ProtocolConstants.MINECRAFT_1_16_2, 0x1D )
);
TO_CLIENT.registerPacket(
ViewDistance.class,
+ ViewDistance::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_14, 0x41 ),
map( ProtocolConstants.MINECRAFT_1_15, 0x42 ),
map( ProtocolConstants.MINECRAFT_1_16, 0x41 )
@@ -268,6 +290,7 @@ public enum Protocol
TO_SERVER.registerPacket(
KeepAlive.class,
+ KeepAlive::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x00 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x0B ),
map( ProtocolConstants.MINECRAFT_1_12, 0x0C ),
@@ -278,6 +301,7 @@ public enum Protocol
);
TO_SERVER.registerPacket(
Chat.class,
+ Chat::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x01 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x02 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x03 ),
@@ -286,6 +310,7 @@ public enum Protocol
);
TO_SERVER.registerPacket(
TabCompleteRequest.class,
+ TabCompleteRequest::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x14 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x01 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x02 ),
@@ -295,6 +320,7 @@ public enum Protocol
);
TO_SERVER.registerPacket(
ClientSettings.class,
+ ClientSettings::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x15 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x04 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x05 ),
@@ -303,6 +329,7 @@ public enum Protocol
);
TO_SERVER.registerPacket(
PluginMessage.class,
+ PluginMessage::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x17 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x09 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x0A ),
@@ -319,19 +346,23 @@ public enum Protocol
{
TO_CLIENT.registerPacket(
StatusResponse.class,
+ StatusResponse::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x00 )
);
TO_CLIENT.registerPacket(
PingPacket.class,
+ PingPacket::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x01 )
);
TO_SERVER.registerPacket(
StatusRequest.class,
+ StatusRequest::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x00 )
);
TO_SERVER.registerPacket(
PingPacket.class,
+ PingPacket::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x01 )
);
}
@@ -343,35 +374,43 @@ public enum Protocol
{
TO_CLIENT.registerPacket(
Kick.class,
+ Kick::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x00 )
);
TO_CLIENT.registerPacket(
EncryptionRequest.class,
+ EncryptionRequest::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x01 )
);
TO_CLIENT.registerPacket(
LoginSuccess.class,
+ LoginSuccess::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x02 )
);
TO_CLIENT.registerPacket(
SetCompression.class,
+ SetCompression::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x03 )
);
TO_CLIENT.registerPacket(
LoginPayloadRequest.class,
+ LoginPayloadRequest::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_13, 0x04 )
);
TO_SERVER.registerPacket(
LoginRequest.class,
+ LoginRequest::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x00 )
);
TO_SERVER.registerPacket(
EncryptionResponse.class,
+ EncryptionResponse::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_8, 0x01 )
);
TO_SERVER.registerPacket(
LoginPayloadResponse.class,
+ LoginPayloadResponse::new, // Waterfall - speed up packet construction
map( ProtocolConstants.MINECRAFT_1_13, 0x02 )
);
}
@@ -422,7 +461,7 @@ public enum Protocol
private final int protocolVersion;
private final TObjectIntMap<Class<? extends DefinedPacket>> packetMap = new TObjectIntHashMap<>( MAX_PACKET_ID );
- private final Constructor<? extends DefinedPacket>[] packetConstructors = new Constructor[ MAX_PACKET_ID ];
+ private final java.util.function.Supplier<? extends DefinedPacket>[] packetConstructors = new java.util.function.Supplier[ MAX_PACKET_ID ]; // Waterfall - speed up packet construction
}
@Data
@@ -490,21 +529,24 @@ public enum Protocol
throw new BadPacketException( "Packet with id " + id + " outside of range " );
}
- Constructor<? extends DefinedPacket> constructor = protocolData.packetConstructors[id];
+ java.util.function.Supplier<? extends DefinedPacket> constructor = protocolData.packetConstructors[id]; // Waterfall - speed up packet construction
try
{
- return ( constructor == null ) ? null : constructor.newInstance();
- } catch ( ReflectiveOperationException ex )
+ return ( constructor == null ) ? null : constructor.get(); // Waterfall - speed up packet construction
+ } catch ( Exception ex ) // Waterfall - speed up packet construction
{
throw new BadPacketException( "Could not construct packet with id " + id, ex );
}
}
- private void registerPacket(Class<? extends DefinedPacket> packetClass, ProtocolMapping... mappings)
+ private <P extends DefinedPacket> void registerPacket(Class<P> packetClass, java.util.function.Supplier<P> constructor, ProtocolMapping... mappings) // Waterfall - speed up packet construction
{
+ // Waterfall start - speed up packet construction
+ /*
try
{
Constructor<? extends DefinedPacket> constructor = packetClass.getDeclaredConstructor();
+ */ // Waterfall end
int mappingIndex = 0;
ProtocolMapping mapping = mappings[mappingIndex];
@@ -533,11 +575,32 @@ public enum Protocol
data.packetMap.put( packetClass, mapping.packetID );
data.packetConstructors[mapping.packetID] = constructor;
}
+ // Waterfall start - speed up packet construction
+ /*
} catch ( NoSuchMethodException ex )
{
throw new BadPacketException( "No NoArgsConstructor for packet class " + packetClass );
}
+ */ // Waterfall end
}
+ // Waterfall start - speed up packet construction (backwards compat)
+ private <P extends DefinedPacket> void registerPacket(Class<P> packetClass, ProtocolMapping... mappings) {
+ java.util.function.Supplier<P> packetSupplier;
+ try {
+ Constructor<? extends DefinedPacket> constructor = packetClass.getDeclaredConstructor();
+ packetSupplier = () -> {
+ try {
+ return (P) constructor.newInstance();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ };
+ } catch (ReflectiveOperationException e) {
+ throw new BadPacketException( "No NoArgsConstructor for packet class " + packetClass );
+ }
+ registerPacket(packetClass, packetSupplier, mappings);
+ }
+ // Waterfall end
final int getId(Class<? extends DefinedPacket> packet, int version)
{
--
2.24.0