From c17587d436c36d5fc801999768e090d223899ee9 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 2 Nov 2021 03:00:00 +0000 Subject: [PATCH] World: use new Vector3() instead of Block->getPosition() When profiling this, I noticed that we spend a stupidly large amount of time creating useless Position objects in the case of update=true, because Vector3->sides() calls Position->getSide(), which calls Position::fromObject(parent::getSide()). This is stupid because the update logic doesn't require Positions anywhere (as evidenced by this change needing no other alterations. A rough profile shows that this improves setBlock() performance by about 25% in the update=true case, which is a pretty big margin. As an added bonus, it gets rid of some unrealized cyclic dependencies in World->changedBlocks. --- src/world/World.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/world/World.php b/src/world/World.php index a6c71cd6f..43768cfc3 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -1600,7 +1600,7 @@ class World implements ChunkManager{ $block->position($this, $x, $y, $z); $block->writeStateToWorld(); - $pos = $block->getPosition(); + $pos = new Vector3($x, $y, $z); $chunkHash = World::chunkHash($chunkX, $chunkZ); $relativeBlockHash = World::chunkBlockHash($x, $y, $z);