refinedmods / refinedstorage

An elegant solution to your hoarding problem.
https://refinedmods.com/refined-storage
MIT License
359 stars 177 forks source link

Build item cache used up too much time #3212

Open Holi0317 opened 2 years ago

Holi0317 commented 2 years ago

Describe the bug

Our server now use around 7 minutes to build RS item cache on bootup. After some profiling, we found out RS is spending too much time on indexing enchanted books in our system. We currently got 464,471 enchanted books in our system.

We made a custom RS build to log out how much time is spent on indexing each item. The analysis is not very accurate as it's just using nanoTime but enchanted books are using 100x time compare to item without NBT and 10x time compare to item with simple NBT.

Profile shows that JVM is spending time on com.refinedmods.refinedstorage.api.util.IComparer#isEqualNoQuantity in method com.refinedmods.refinedstorage.apiimpl.util.ItemStackList#add(net.minecraft.item.ItemStack, int). One possible solution would be disable item stacking for hard-coded/configerable list of items. That may solve the performance issue with stacking large NBT items.

How can we reproduce this bug or crash?

  1. Put large amount of enchanted book in RS system
  2. Reboot server

What Minecraft version is this happening on?

Minecraft 1.16.5 (Enigmatica6 0.5.21)

What Forge version is this happening on?

36.2.22

What Refined Storage version is this happening on?

1.9.16

Relevant log output

No response

HeatherComputer commented 2 years ago

I fixed this personally with a mixin mod that only invalidated networks once per tick - ideally this should be integrated into RS itself soon though. It's available at https://github.com/RaVenInTheDark/RSFreezeFix/releases/tag/1.0, and it's open source with an MIT license so there should be zero issue in porting it directly (although there's probably better methods.)

I've tested this on an e6 server and it dropped 15+ minute first tick times to mere seconds, with no issues found so far.