BlockStateDictionary: slash another 14% off memory usage by deduplicating block type names

perhaps we could construct a dictionary from BlockTypeNames reflection??
This commit is contained in:
Dylan K. Taylor 2023-05-03 23:14:53 +01:00
parent ed021d193d
commit f9d9cbd0f6
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 9 additions and 5 deletions

View File

@ -130,6 +130,7 @@ final class BlockStateDictionary{
$entries = [];
$uniqueNames = [];
foreach(self::loadPaletteFromString($blockPaletteContents) as $i => $state){
$meta = $metaMap[$i] ?? null;
if($meta === null){
@ -138,7 +139,8 @@ final class BlockStateDictionary{
if(!is_int($meta)){
throw new \InvalidArgumentException("Invalid metaMap offset $i, expected int, got " . get_debug_type($meta));
}
$entries[$i] = new BlockStateDictionaryEntry($state, $meta);
$uniqueName = $uniqueNames[$state->getName()] ??= $state->getName();
$entries[$i] = new BlockStateDictionaryEntry($uniqueName, $state->getStates(), $meta);
}
return new self($entries);

View File

@ -34,15 +34,17 @@ use const SORT_STRING;
final class BlockStateDictionaryEntry{
private string $stateName;
private string $rawStateProperties;
/**
* @param Tag[] $stateProperties
*/
public function __construct(
BlockStateData $stateData,
private string $stateName,
array $stateProperties,
private int $meta
){
$this->stateName = $stateData->getName();
$this->rawStateProperties = self::encodeStateProperties($stateData->getStates());
$this->rawStateProperties = self::encodeStateProperties($stateProperties);
}
public function getStateName() : string{ return $this->stateName; }