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

Optimize NBT comparisons by caching the hash code for NBTagCompound and NBTTagList #497

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kurrycat2004
Copy link
Contributor

The cached hash code is calculated lazily, so the only way this could potentially perform worse is when TagCompounds/TagLists that are equal (but not copied) are compared exactly once, as in that case it now also calculates the hash code instead of just directly comparing.
But this should realistically happen very rarely, if ever, and for 2+ comparisons it should be faster (or at least not slower), because it'll use the cached hash code to early return.
I wasn't really able to profile the performance gain, so if anyone wants to, go for it.
But i imagine that this impacts stuff like ItemStack comparisons the most.

@Dream-Master Dream-Master requested a review from a team March 17, 2025 17:27
@Dream-Master
Copy link
Member

@kurrycat2004 can you run spotless.

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.

2 participants