Store binary-encoded simple tags inside CompoundTag
and ListTag
instead of useless boxing objects
#126
Labels
CompoundTag
and ListTag
instead of useless boxing objects
#126
User code rarely interacts with the likes of
IntTag
directly. It's also horribly inefficient to box integers this way.In addition, extra objects means extra work for the GC.
All simple tags (byte, short, int, long, string, byte[], float, double, int[]) could be easily stored as
string
insideCompoundTag
andListTag
, avoiding the need for a ton of unnecessary object allocations. This string would essentially just bechr($tagType) . LittleEndianNbtSerializer::writeHeadless($tagValue)
.Brief investigation shows that integer-like tags
ByteTag
,ShortTag
, etc take up a minimum of80
bytes of memory. Encoded as strings, these would take32
bytes each instead (the aligned size ofzend_string
).StringTag
,ByteArrayTag
andIntTag
would be larger (depending on the size of their contained values).(We could even use
int
for types smaller than 8 bytes on 64-bit platforms, which would avoid extra allocations completely.)The only potential caveat to this is that packing the values into a binary form would be kinda slow because the NBT serializers currently have crap performance. However, it's possible that the cost of allocating
Tag
objects might outweigh this anyway.There's also the consideration that if
CompoundTag->getTag()
orgetValue()
were used, we'd have to convert the strings into tag objects anyway. So this would mostly benefit from use of stuff likeCompoundTag->getInt()
where we could just directly convert the internalstring
binary into anint
value without allocating any objects.The text was updated successfully, but these errors were encountered: