13
0
geforkt von Mirrors/Velocity

Small optimization for writing packets to the client from the server

The layers of indirection to get to the MinecraftConnection causes a
small, but not insignificant hit to performance.
Dieser Commit ist enthalten in:
Andrew Steinborn 2019-05-21 00:33:35 -04:00
Ursprung a684aaa325
Commit b09331b79b

Datei anzeigen

@ -31,14 +31,15 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
private final VelocityServer server; private final VelocityServer server;
private final VelocityServerConnection serverConn; private final VelocityServerConnection serverConn;
private final ClientPlaySessionHandler playerSessionHandler; private final ClientPlaySessionHandler playerSessionHandler;
private final MinecraftConnection playerConnection;
private boolean exceptionTriggered = false; private boolean exceptionTriggered = false;
BackendPlaySessionHandler(VelocityServer server, VelocityServerConnection serverConn) { BackendPlaySessionHandler(VelocityServer server, VelocityServerConnection serverConn) {
this.server = server; this.server = server;
this.serverConn = serverConn; this.serverConn = serverConn;
this.playerConnection = serverConn.getPlayer().getMinecraftConnection();
MinecraftSessionHandler psh = serverConn.getPlayer().getMinecraftConnection() MinecraftSessionHandler psh = playerConnection.getSessionHandler();
.getSessionHandler();
if (!(psh instanceof ClientPlaySessionHandler)) { if (!(psh instanceof ClientPlaySessionHandler)) {
throw new IllegalStateException( throw new IllegalStateException(
"Initializing BackendPlaySessionHandler with no backing client play session handler!"); "Initializing BackendPlaySessionHandler with no backing client play session handler!");
@ -104,7 +105,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
if (PluginMessageUtil.isMcBrand(packet)) { if (PluginMessageUtil.isMcBrand(packet)) {
PluginMessage rewritten = PluginMessageUtil.rewriteMinecraftBrand(packet, PluginMessage rewritten = PluginMessageUtil.rewriteMinecraftBrand(packet,
server.getVersion()); server.getVersion());
serverConn.getPlayer().getMinecraftConnection().write(rewritten); playerConnection.write(rewritten);
return true; return true;
} }
@ -118,15 +119,14 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
return false; return false;
} }
MinecraftConnection clientConn = serverConn.getPlayer().getMinecraftConnection();
PluginMessageEvent event = new PluginMessageEvent(serverConn, serverConn.getPlayer(), id, PluginMessageEvent event = new PluginMessageEvent(serverConn, serverConn.getPlayer(), id,
packet.getData()); packet.getData());
server.getEventManager().fire(event) server.getEventManager().fire(event)
.thenAcceptAsync(pme -> { .thenAcceptAsync(pme -> {
if (pme.getResult().isAllowed() && !clientConn.isClosed()) { if (pme.getResult().isAllowed() && !playerConnection.isClosed()) {
clientConn.write(packet); playerConnection.write(packet);
} }
}, clientConn.eventLoop()); }, playerConnection.eventLoop());
return true; return true;
} }
@ -163,12 +163,12 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
@Override @Override
public void handleGeneric(MinecraftPacket packet) { public void handleGeneric(MinecraftPacket packet) {
serverConn.getPlayer().getMinecraftConnection().write(packet); playerConnection.write(packet);
} }
@Override @Override
public void handleUnknown(ByteBuf buf) { public void handleUnknown(ByteBuf buf) {
serverConn.getPlayer().getMinecraftConnection().write(buf.retain()); playerConnection.write(buf.retain());
} }
@Override @Override