geforkt von Mirrors/Velocity
Reduce unnecessary memory copies in StatusSessionHandler
Take advantage of the fact that Java has mutable strings when writing out server ping responses, which Netty can work with when writing out UTF-8 character sequences. This reduces the memory allocation impact of server list ping responses by ~31%.
Dieser Commit ist enthalten in:
Ursprung
3cee15a9cb
Commit
df9883cc6c
@ -69,7 +69,11 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
||||
ProxyPingEvent event = new ProxyPingEvent(inboundWrapper, initialPing);
|
||||
server.getEventManager().fire(event)
|
||||
.thenRunAsync(
|
||||
() -> connection.write(new StatusResponse(VelocityServer.GSON.toJson(event.getPing()))),
|
||||
() -> {
|
||||
StringBuilder json = new StringBuilder();
|
||||
VelocityServer.GSON.toJson(event.getPing(), json);
|
||||
connection.write(new StatusResponse(json));
|
||||
},
|
||||
connection.eventLoop());
|
||||
return true;
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ public enum ProtocolUtils {
|
||||
* @param buf the buffer to write to
|
||||
* @param str the string to write
|
||||
*/
|
||||
public static void writeString(ByteBuf buf, String str) {
|
||||
public static void writeString(ByteBuf buf, CharSequence str) {
|
||||
int size = ByteBufUtil.utf8Bytes(str);
|
||||
writeVarInt(buf, size);
|
||||
ByteBufUtil.writeUtf8(buf, str);
|
||||
|
@ -9,12 +9,12 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class StatusResponse implements MinecraftPacket {
|
||||
|
||||
private @Nullable String status;
|
||||
private @Nullable CharSequence status;
|
||||
|
||||
public StatusResponse() {
|
||||
}
|
||||
|
||||
public StatusResponse(String status) {
|
||||
public StatusResponse(CharSequence status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ public class StatusResponse implements MinecraftPacket {
|
||||
if (status == null) {
|
||||
throw new IllegalStateException("Status is not specified");
|
||||
}
|
||||
return status;
|
||||
return status.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren