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.
The
isSimilarPotion
is very expensive because the code attempts to get theotherPotion
(in this case, the current item)ItemMeta
on every comparison check, and initializing theItemMeta
is very expensive.To avoid this, we only create the
ItemMeta
once and then reuse it in theisSimilarPotion
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.