mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 17:29:44 +00:00
Use compression level 0 when batch size is below threshold
This isn't free, because of the adler32 checksum... but it's much lighter on performance for small packets.
This commit is contained in:
parent
b7b7bcee4f
commit
c6e800cf42
@ -1783,17 +1783,7 @@ class Server{
|
||||
public function broadcastPacket(array $players, DataPacket $packet){
|
||||
$packet->encode();
|
||||
$packet->isEncoded = true;
|
||||
if(Network::$BATCH_THRESHOLD >= 0 and strlen($packet->buffer) >= Network::$BATCH_THRESHOLD){
|
||||
$this->batchPackets($players, [$packet], false);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach($players as $player){
|
||||
$player->dataPacket($packet);
|
||||
}
|
||||
if(isset($packet->__encapsulatedPacket)){
|
||||
unset($packet->__encapsulatedPacket);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1821,11 +1811,17 @@ class Server{
|
||||
$pk->addPacket($p);
|
||||
}
|
||||
|
||||
if(Network::$BATCH_THRESHOLD >= 0 and strlen($pk->payload) >= Network::$BATCH_THRESHOLD){
|
||||
$compressionLevel = $this->networkCompressionLevel;
|
||||
}else{
|
||||
$compressionLevel = 0; //Do not compress packets under the threshold
|
||||
}
|
||||
|
||||
if(!$forceSync and !$immediate and $this->networkCompressionAsync){
|
||||
$task = new CompressBatchedTask($pk, $targets, $this->networkCompressionLevel);
|
||||
$task = new CompressBatchedTask($pk, $targets, $compressionLevel);
|
||||
$this->getScheduler()->scheduleAsyncTask($task);
|
||||
}else{
|
||||
$pk->compress($this->networkCompressionLevel);
|
||||
$pk->compress($compressionLevel);
|
||||
$this->broadcastPacketsCallback($pk, $targets, $immediate);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user