Skip to content

Commit

Permalink
RakLibServer: disable GC
Browse files Browse the repository at this point in the history
GC is not required for RakLib as it doesn't generate any unmanaged cycles.
Cycles in general do exist (e.g. Server <-> ServerSession), but these are
explicitly cleaned up, so GC wouldn't have any useful work to do.
  • Loading branch information
dktapps committed Dec 19, 2024
1 parent aee358d commit fea17fa
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/network/mcpe/raklib/RakLibServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
use raklib\server\SimpleProtocolAcceptor;
use raklib\utils\ExceptionTraceCleaner;
use raklib\utils\InternetAddress;
use function gc_enable;
use function gc_disable;
use function ini_set;

class RakLibServer extends Thread{
Expand Down Expand Up @@ -82,10 +82,9 @@ public function startAndWait(int $options = NativeThread::INHERIT_NONE) : void{
}

protected function onRun() : void{
//TODO: switch to manually triggered GC
//the best time to do it is between ticks when the server would otherwise be sleeping, but RakLib's current
//design doesn't allow this as of 1.1.1
gc_enable();
//RakLib has cycles (e.g. ServerSession <-> Server) but these cycles are explicitly cleaned up anyway, and are
//very few, so it's pointless to waste CPU time on GC
gc_disable();

ini_set("display_errors", '1');
ini_set("display_startup_errors", '1');
Expand Down

0 comments on commit fea17fa

Please sign in to comment.