mirror of https://github.com/Minestom/Minestom.git
slightly improve performance and fix memory leak
This commit is contained in:
parent
414245a1a6
commit
d056fceb8a
|
@ -104,20 +104,20 @@ public final class BenchmarkManager {
|
|||
}
|
||||
|
||||
public String getCpuMonitoringMessage() {
|
||||
String benchmarkMessage = "";
|
||||
StringBuilder benchmarkMessage = new StringBuilder();
|
||||
for (Map.Entry<String, ThreadResult> resultEntry : resultMap.entrySet()) {
|
||||
final String name = resultEntry.getKey();
|
||||
final ThreadResult result = resultEntry.getValue();
|
||||
|
||||
benchmarkMessage += ChatColor.GRAY + name;
|
||||
benchmarkMessage += ": ";
|
||||
benchmarkMessage += ChatColor.YELLOW.toString() + MathUtils.round(result.getCpuPercentage(), 2) + "% CPU ";
|
||||
benchmarkMessage += ChatColor.RED.toString() + MathUtils.round(result.getUserPercentage(), 2) + "% USER ";
|
||||
benchmarkMessage += ChatColor.PINK.toString() + MathUtils.round(result.getBlockedPercentage(), 2) + "% BLOCKED ";
|
||||
benchmarkMessage += ChatColor.BRIGHT_GREEN.toString() + MathUtils.round(result.getWaitedPercentage(), 2) + "% WAITED ";
|
||||
benchmarkMessage += "\n";
|
||||
benchmarkMessage.append(ChatColor.GRAY).append(name);
|
||||
benchmarkMessage.append(": ");
|
||||
benchmarkMessage.append(ChatColor.YELLOW.toString()).append(MathUtils.round(result.getCpuPercentage(), 2)).append("% CPU ");
|
||||
benchmarkMessage.append(ChatColor.RED.toString()).append(MathUtils.round(result.getUserPercentage(), 2)).append("% USER ");
|
||||
benchmarkMessage.append(ChatColor.PINK.toString()).append(MathUtils.round(result.getBlockedPercentage(), 2)).append("% BLOCKED ");
|
||||
benchmarkMessage.append(ChatColor.BRIGHT_GREEN.toString()).append(MathUtils.round(result.getWaitedPercentage(), 2)).append("% WAITED ");
|
||||
benchmarkMessage.append("\n");
|
||||
}
|
||||
return benchmarkMessage;
|
||||
return benchmarkMessage.toString();
|
||||
}
|
||||
|
||||
private void refreshData() {
|
||||
|
|
|
@ -13,10 +13,6 @@ public class GroupedPacketHandler extends MessageToByteEncoder<FramedPacket> {
|
|||
|
||||
out.setBytes(0, packet, 0, packet.writerIndex());
|
||||
out.writerIndex(packet.writerIndex());
|
||||
|
||||
if (msg.releaseBuf) {
|
||||
packet.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,15 +10,9 @@ import org.jetbrains.annotations.NotNull;
|
|||
public class FramedPacket {
|
||||
|
||||
public final ByteBuf body;
|
||||
public boolean releaseBuf = false;
|
||||
|
||||
public FramedPacket(@NotNull ByteBuf body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public FramedPacket(@NotNull ByteBuf body, boolean releaseBuf) {
|
||||
this.body = body;
|
||||
this.releaseBuf = releaseBuf;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public final class PacketUtils {
|
|||
final boolean success = PACKET_LISTENER_MANAGER.processServerPacket(packet, players);
|
||||
if (success) {
|
||||
final ByteBuf finalBuffer = createFramedPacket(packet, true);
|
||||
final FramedPacket framedPacket = new FramedPacket(finalBuffer, true);
|
||||
final FramedPacket framedPacket = new FramedPacket(finalBuffer);
|
||||
|
||||
final int refIncrease = players.size() - 1;
|
||||
if (refIncrease > 0)
|
||||
|
@ -55,7 +55,7 @@ public final class PacketUtils {
|
|||
final PlayerConnection playerConnection = player.getPlayerConnection();
|
||||
if (playerConnection instanceof NettyPlayerConnection) {
|
||||
final NettyPlayerConnection nettyPlayerConnection = (NettyPlayerConnection) playerConnection;
|
||||
nettyPlayerConnection.write(framedPacket);
|
||||
nettyPlayerConnection.getChannel().write(framedPacket).addListener((p) -> finalBuffer.release());
|
||||
} else {
|
||||
playerConnection.sendPacket(packet);
|
||||
finalBuffer.release();
|
||||
|
|
|
@ -175,7 +175,7 @@ public class PlayerInit {
|
|||
event.setSpawningInstance(instanceContainer);
|
||||
int x = Math.abs(ThreadLocalRandom.current().nextInt()) % 2000 - 1000;
|
||||
int z = Math.abs(ThreadLocalRandom.current().nextInt()) % 2000 - 1000;
|
||||
player.setRespawnPoint(new Position(0, 70f, 0));
|
||||
player.setRespawnPoint(new Position(x, 70f, z));
|
||||
|
||||
player.getInventory().addInventoryCondition((p, slot, clickType, inventoryConditionResult) -> {
|
||||
if (slot == -999)
|
||||
|
|
Loading…
Reference in New Issue