mcMMO-Dev / mcMMO

The RPG Lover's Mod!
https://mcmmo.org
GNU General Public License v3.0
1.01k stars 868 forks source link

Cache ItemMeta instead of creating a new ItemMeta for each potion check #5075

Closed MrPowerGamerBR closed 2 months ago

MrPowerGamerBR commented 2 months ago

The isSimilarPotion is very expensive because the code attempts to get the otherPotion (in this case, the current item) ItemMeta on every comparison check, and initializing the ItemMeta is very expensive.

To avoid this, we only create the ItemMeta once and then reuse it in the isSimilarPotion check.

While on Spigot the ItemStack code does seem to cache the ItemMeta, on Paper it doesn't due to the ItemStack being delegated to the server ItemStack, the ItemMeta seems to be always be created on every getItemMeta() call.

image

nossr50 commented 2 months ago

Thank you, I appreciate it!