Skip to content

CompressionThreadDispatcher 5.46.0 ​

final class · pocketmine\network\mcpe\compression\CompressionThreadDispatcher · source

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() ​

php
public function __construct(\pocketmine\network\mcpe\compression\Compressor $compressor, \pocketmine\snooze\SleeperHandler $sleeper, \pocketmine\thread\log\ThreadSafeLogger $logger, ?array $classLoaders = null)

collectResults() ​

php
public function collectResults() : void

Resolves the promises of the batches the thread has finished. Called when the thread wakes the main thread up.

getCompressor() ​

php
public function getCompressor() : \pocketmine\network\mcpe\compression\Compressor

getPendingCount() ​

php
public function getPendingCount() : int

isAvailable() ​

php
public function isAvailable() : bool

Returns whether batches can be handed to the thread (it is running and not shutting down).

shutdown() ​

php
public function shutdown() : void

Stops the thread. Batches it did not get to are compressed here, so nothing queued is lost.

submit() ​

php
public function submit(string $buffer) : \pocketmine\network\mcpe\compression\CompressBatchPromise

Hands a batch to the thread. The promise is resolved on the main thread with the compressed batch (algorithm byte included), in submission order.

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.