mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 00:07:30 +00:00
Fixed performance bug with chunk sending
this process of fast-serialization, fast-deserialize, network-serialize is an order of magnitude slower than just doing the network encode directly on the main thread, and also copies more useless data. For the main thread, the figures were something like 3x more expensive, and then an extra 7x for deserialization on the worker thread. This is a ridiculously large overhead.
This commit is contained in:
parent
f0182c9996
commit
6b9fee05d6
@ -29,7 +29,6 @@ use pocketmine\network\mcpe\protocol\BatchPacket;
|
||||
use pocketmine\network\mcpe\protocol\FullChunkDataPacket;
|
||||
use pocketmine\scheduler\AsyncTask;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\tile\Spawnable;
|
||||
|
||||
class ChunkRequestTask extends AsyncTask{
|
||||
|
||||
@ -39,36 +38,22 @@ class ChunkRequestTask extends AsyncTask{
|
||||
protected $chunkX;
|
||||
protected $chunkZ;
|
||||
|
||||
protected $tiles;
|
||||
|
||||
protected $compressionLevel;
|
||||
|
||||
public function __construct(Level $level, int $chunkX, int $chunkZ, Chunk $chunk){
|
||||
$this->levelId = $level->getId();
|
||||
$this->compressionLevel = $level->getServer()->networkCompressionLevel;
|
||||
|
||||
$this->chunk = $chunk->fastSerialize();
|
||||
$this->chunk = $chunk->networkSerialize();
|
||||
$this->chunkX = $chunkX;
|
||||
$this->chunkZ = $chunkZ;
|
||||
|
||||
//TODO: serialize tiles with chunks
|
||||
$tiles = "";
|
||||
foreach($chunk->getTiles() as $tile){
|
||||
if($tile instanceof Spawnable){
|
||||
$tiles .= $tile->getSerializedSpawnCompound();
|
||||
}
|
||||
}
|
||||
|
||||
$this->tiles = $tiles;
|
||||
}
|
||||
|
||||
public function onRun(){
|
||||
$chunk = Chunk::fastDeserialize($this->chunk);
|
||||
|
||||
$pk = new FullChunkDataPacket();
|
||||
$pk->chunkX = $this->chunkX;
|
||||
$pk->chunkZ = $this->chunkZ;
|
||||
$pk->data = $chunk->networkSerialize() . $this->tiles;
|
||||
$pk->data = $this->chunk;
|
||||
|
||||
$batch = new BatchPacket();
|
||||
$batch->addPacket($pk);
|
||||
|
Loading…
x
Reference in New Issue
Block a user