Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store immutable tags internally as plain values #131

Open
wants to merge 6 commits into
base: stable
Choose a base branch
from

Conversation

dktapps
Copy link
Member

@dktapps dktapps commented Mar 11, 2025

This PR implements #126.

The memory usage improvement is very slim according to initial tests - sadly the gains from not allocating the simple tag objects are negated by the losses from having a separate valueTypes array in CompoundTag.
Write performance is also marginally worse because of the extra array lookup in CompoundTag->valueTypes.

However, the performance of decoding is improved by about 10%, and equals() is more than 2x faster.

This architecture would favour implementing NBT as a PHP extension, since we'd be able to do considerably more optimizations at the native level than we can here.

this improves performance of decode & compare since there's less levels of indirection and also no need to allocate useless objects.
since we generally use the CompoundTag special-type methods anyway it means we can avoid a lot of object creations if the expected type is only one type.

Memory usage should also benefit, but I haven't had a chance to do detailed profiling yet.
@dktapps dktapps requested a review from a team as a code owner March 11, 2025 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant