From ab37df4484d77414018383e33bc7bd0289230c39 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 6 Jan 2019 01:08:56 +0000 Subject: [PATCH] Server: micro-optimization: avoid unnecessary array_shift() it's much less expensive to just calculate the modulo of the current tick and 20, and overwrite past entries. The effect is the same. The only difference is that the arrays won't be ordered by time, but that doesn't matter anyway. --- src/pocketmine/Server.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 14b92e232..ed5f26b96 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -2649,10 +2649,9 @@ class Server{ TimingsHandler::tick($this->currentTPS <= $this->profilingTickRate); - array_shift($this->tickAverage); - $this->tickAverage[] = $this->currentTPS; - array_shift($this->useAverage); - $this->useAverage[] = $this->currentUse; + $idx = $this->tickCounter % 20; + $this->tickAverage[$idx] = $this->currentTPS; + $this->useAverage[$idx] = $this->currentUse; if(($this->nextTick - $tickTime) < -1){ $this->nextTick = $tickTime;