Shadows-of-Fire / Apotheosis

All things that should have been.
Other
151 stars 119 forks source link

Item `getHoverName` hitting JSON deserialization, impacting performance when sorting storage by item name #1229

Closed pollyzoid closed 1 month ago

pollyzoid commented 2 months ago

Not a straightforward bug. apoth_affixItemName mixin for ItemStack is calling AffixHelper.getName, which deserializes NBT data (?) with GSON. It's not an especially fast library for reading JSON, so it's impacting sorting performance in storage.

Disclaimer: no MC modding experience.

I discovered this when looking into a Spark profile when another mod was causing massive client lag spikes when browsing its storage system. While the lag was caused mainly by its (presumably) bugged system sorting the item list constantly, a big factor in the lag was very frequent calls to ItemStack.getHoverName due to it being used in the comparison function. Even in unexceptional usage, sorting a large storage with tools/weapons/armor like Functional Storage's Armory Cabinet by name, this would be causing a spike in tick duration.

Would it be feasible to either cache this sort of frequently accessed data, or alternatively use a faster JSON library like fastjson?

Minecraft 1.19.2 Apotheosis 6.5.0 Profile in question: https://spark.lucko.me/ydCYeLPeUr

Shadows-of-Fire commented 1 month ago

The mixin you see there is just to isolate the affix name parts from the main name - the json logic is all from vanilla. This will happen to any items with custom names and should be considered the fault of the sorting system for calling it so frequently. While there is theoretically some caching logic I can apply, 1.19 is not receiving non-critical changes, and vanilla's move to item components in 1.21 makes this a non-issue going forward.