From 8ec304e66e489b1dd4d4c2f7b6493e70212a01e3 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 12 Mar 2024 11:45:08 +0000 Subject: [PATCH] BlockStateUpgradeSchema: avoid unnecessary property access and calculation this was costing a surprisingly large 5-10% of the processing time for blockstate data. --- .../block/upgrade/BlockStateUpgradeSchema.php | 16 ++++++++++------ .../bedrock/block/upgrade/BlockStateUpgrader.php | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/data/bedrock/block/upgrade/BlockStateUpgradeSchema.php b/src/data/bedrock/block/upgrade/BlockStateUpgradeSchema.php index 36960383e..6d280ecf7 100644 --- a/src/data/bedrock/block/upgrade/BlockStateUpgradeSchema.php +++ b/src/data/bedrock/block/upgrade/BlockStateUpgradeSchema.php @@ -64,20 +64,24 @@ final class BlockStateUpgradeSchema{ */ public array $remappedStates = []; + public readonly int $versionId; + public function __construct( - public int $maxVersionMajor, - public int $maxVersionMinor, - public int $maxVersionPatch, - public int $maxVersionRevision, + public readonly int $maxVersionMajor, + public readonly int $maxVersionMinor, + public readonly int $maxVersionPatch, + public readonly int $maxVersionRevision, private int $schemaId - ){} + ){ + $this->versionId = ($this->maxVersionMajor << 24) | ($this->maxVersionMinor << 16) | ($this->maxVersionPatch << 8) | $this->maxVersionRevision; + } /** * @deprecated This is defined by Mojang, and therefore cannot be relied on. Use getSchemaId() instead for * internal version management. */ public function getVersionId() : int{ - return ($this->maxVersionMajor << 24) | ($this->maxVersionMinor << 16) | ($this->maxVersionPatch << 8) | $this->maxVersionRevision; + return $this->versionId; } public function getSchemaId() : int{ return $this->schemaId; } diff --git a/src/data/bedrock/block/upgrade/BlockStateUpgrader.php b/src/data/bedrock/block/upgrade/BlockStateUpgrader.php index f8574d6a2..e91a5cf60 100644 --- a/src/data/bedrock/block/upgrade/BlockStateUpgrader.php +++ b/src/data/bedrock/block/upgrade/BlockStateUpgrader.php @@ -62,7 +62,7 @@ final class BlockStateUpgrader{ $version = $blockStateData->getVersion(); $highestVersion = $version; foreach($this->upgradeSchemas as $schema){ - $resultVersion = $schema->getVersionId(); + $resultVersion = $schema->versionId; $highestVersion = max($highestVersion, $resultVersion); if($version > $resultVersion){ //even if this is actually the same version, we have to apply it anyway because mojang are dumb and