![Curios API Continuation [Frozen]](https://media.forgecdn.net/avatars/thumbnails/1017/129/256/256/638543265839292912_animated.gif)
[Feature]: Performance Improvements
lcy0x1 opened this issue · 1 comments
What is the new feature or improvement?
Curios in 1.20.1 has a huge performance cost due to 3 reasons:
- Retrieving capability from entities (already addressed by the Attachment system)
- All mods are iterating over all slots
- Some methods are called far too frequently
My suggestion:
- EnderMask could be called probably hundreds of times per tick, when player is in the end. It could be causing a lot of lag. One way to address it is to split ender mask method into 2 methods:
isEnderMask()
with result{YES, DEPENDS, NO}
andboolean isEnderMask(ItemStack, LivingEntity, EnderMan)
if it returnsDEPENDS
. This allows curios to cache the value if nobody returnsDEPENDS
and make this part 100+ times faster. - A lot of mods are just trying to query
boolean contains(Item)
orboolean contains(TagKey<Item>)
. These 2 use cases can be cached to reduce slot iterations. Queries can be cached and invalidated when curios changed on player (or rebuild cache per tick, which is enough already). - For use cases such as
Optional<ItemStack> findFirst(Item)
, instead of iterating through all slots, it could be faster if it's just iterating over slots that could contain the item, by checking which curios tags the item has (pluscurios
slot). I tried it in my 1.20.1 mods, and it reduced mspt of my mod by 50%, with the remaining 50% coming from capability fetch and ResourceLocation validation. I believe those can be addressed in 1.21 as well. - If suggestion 2 and 3 were to be implemented, I would recommend to deprecate previous methods to encourage mod devs to use the better performing methods.
Curios is currently consuming 5%~8% of game mspt in large adventure oriented modpacks, being the top 5 of resource intensive mods in modpack of 200+ mods, higher than AlexMobs and IceAndFire. These performance costs are primarily induced by other mods constantly fetching and checking curios, so it’s hard to test without a mature large modpack. This improvement could help a lot to improve performance.
These changes were discussed with C4 and reached an agreement that it’s too much of a breaking change for 1.20.1 and better to leave it for next Minecraft version. Now this is a chance to make Curios performing better.