CompressionThreadDispatcher 5.46.0
Main-thread side of the CompressionThread: every packet batch of every session is compressed once per tick, and with many players close together (every movement goes to every viewer) that compression grows with the square of the player count. The thread takes it off the main thread; the main thread only hands the batches over and sends the results when the thread wakes it (while it sleeps between ticks, or at the start of the next tick when it is overloaded).
Unlike async-compression (an AsyncTask per batch, only worth it for big batches), a job here costs the main thread a few microseconds, so every batch above the compression threshold goes through it.
Methods
__construct()
public function __construct(\pocketmine\network\mcpe\compression\Compressor $compressor, \pocketmine\snooze\SleeperHandler $sleeper, \pocketmine\thread\log\ThreadSafeLogger $logger, ?array $classLoaders = null)collectResults()
public function collectResults() : voidResolves the promises of the batches the thread has finished. Called when the thread wakes the main thread up.
getCompressor()
public function getCompressor() : \pocketmine\network\mcpe\compression\CompressorgetPendingCount()
public function getPendingCount() : intisAvailable()
public function isAvailable() : boolReturns whether batches can be handed to the thread (it is running and not shutting down).
shutdown()
public function shutdown() : voidStops the thread. Batches it did not get to are compressed here, so nothing queued is lost.
submit()
public function submit(string $buffer) : \pocketmine\network\mcpe\compression\CompressBatchPromiseHands a batch to the thread. The promise is resolved on the main thread with the compressed batch (algorithm byte included), in submission order.
