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.
This commit is contained in:
Dylan K. Taylor 2021-11-02 03:00:00 +00:00
parent 0f6b7e48cb
commit c17587d436
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -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);