mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
NetworkSession: store Packet[] for buffering instead of PacketBatch
this reduces memory allocations for buffering (in theory).
This commit is contained in:
parent
ed144a1709
commit
2fcee432c1
@ -151,8 +151,8 @@ class NetworkSession{
|
||||
/** @var EncryptionContext */
|
||||
private $cipher;
|
||||
|
||||
/** @var PacketBatch|null */
|
||||
private $sendBuffer;
|
||||
/** @var Packet[] */
|
||||
private $sendBuffer = [];
|
||||
|
||||
/**
|
||||
* @var \SplQueue|CompressBatchPromise[]
|
||||
@ -416,10 +416,7 @@ class NetworkSession{
|
||||
$timings = Timings::getSendDataPacketTimings($packet);
|
||||
$timings->startTiming();
|
||||
try{
|
||||
if($this->sendBuffer === null){
|
||||
$this->sendBuffer = new PacketBatch();
|
||||
}
|
||||
$this->sendBuffer->putPacket($packet);
|
||||
$this->sendBuffer[] = $packet;
|
||||
$this->manager->scheduleUpdate($this); //schedule flush at end of tick
|
||||
}finally{
|
||||
$timings->stopTiming();
|
||||
@ -427,9 +424,9 @@ class NetworkSession{
|
||||
}
|
||||
|
||||
private function flushSendBuffer(bool $immediate = false) : void{
|
||||
if($this->sendBuffer !== null){
|
||||
$promise = $this->server->prepareBatch($this->sendBuffer, $this->compressor, $immediate);
|
||||
$this->sendBuffer = null;
|
||||
if(count($this->sendBuffer) > 0){
|
||||
$promise = $this->server->prepareBatch(PacketBatch::fromPackets(...$this->sendBuffer), $this->compressor, $immediate);
|
||||
$this->sendBuffer = [];
|
||||
$this->queueCompressed($promise, $immediate);
|
||||
}
|
||||
}
|
||||
@ -944,9 +941,7 @@ class NetworkSession{
|
||||
return true; //keep ticking until timeout
|
||||
}
|
||||
|
||||
if($this->sendBuffer !== null){
|
||||
$this->flushSendBuffer();
|
||||
}
|
||||
$this->flushSendBuffer();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user