From 6b9fee05d6dfcb2e516ba106bf6e60637ae1f274 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 3 Nov 2018 15:12:22 +0000 Subject: [PATCH] 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. --- .../level/format/io/ChunkRequestTask.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/pocketmine/level/format/io/ChunkRequestTask.php b/src/pocketmine/level/format/io/ChunkRequestTask.php index ef451e4b5..16fb7370f 100644 --- a/src/pocketmine/level/format/io/ChunkRequestTask.php +++ b/src/pocketmine/level/format/io/ChunkRequestTask.php @@ -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);