Lothrazar / Cyclic

Minecraft mod written in Java
MIT License
166 stars 97 forks source link

[1.18.2][1.20.1] Cyclic AntiBeacon effect code runs on every status effect adding, leading to lag with certain mods #2269

Closed TelepathicGrunt closed 11 months ago

TelepathicGrunt commented 1 year ago

Someone reported an issue to my mod Bumblezone for 1.18.2 (I dropped support for 1.18.2). https://github.com/TelepathicGrunt/Bumblezone/issues/240

They stated that when Spiders are in my Stick Honey Residue or Sticky Honey Web, my code to add the slowness effect to the mob was lagging the server from 20tps to 80tps. They showed a log that seems to point to Cyclic running an event every time an effect is added to a mob and in this event, Cyclic is doing an expensive blockstate lookup that is leading to the tps to skyrocket. From the name of the methods, it seems you do a scan to look for a nearby AntiBeacon block?

   net.minecraftforge.eventbus.ASMEventHandler_2960_PotionEvents_isPotionApplicable_PotionApplicableEvent.invoke()55.44%                                                         
   com.lothrazar.cyclic.event.PotionEvents.isPotionApplicable()55.44%                                                                                    
   com.lothrazar.cyclic.block.antipotion.BlockAntiBeacon.isPotionApplicable()55.44%              
   com.lothrazar.cyclic.util.BlockstatesUtil.findBlocks()55.44%                                                                                                                                                                    
   net.minecraft.world.level.Level.getBlockState()55.44%

Are you positive there is no other solution or better way of doing this that can skip doing a blockstate lookup? Have you considered trying making a Point of Interest for your antibeacon and use that to scan for if your block is nearby and in range. The POI system is made for this and should be much more performant than blockstate lookups. Example of a POI usage:

https://github.com/TelepathicGrunt/Bumblezone/blob/ee6f82965cd648970dbeeca569b0752bc72f04c3/src/main/java/com/telepathicgrunt/the_bumblezone/effects/WrathOfTheHiveEffect.java#L139-L148

Reshy commented 1 year ago

Thanks for submitting this here Telepathic, I was about to do it myself.

TelepathicGrunt commented 1 year ago

Issue affects 1.20.1 as well. I have gotten a report about this today image

drakray commented 1 year ago

I have something very similar on 1.20.1, where if I try to pregen the Bumblezone dimension the game deadlock, and I must kill the process to exit

drakray commented 1 year ago

it seems that setting harmful_potions = false in config/cyclic.toml fixes, at least temporarily, the problem, without removing Cyclic from the mod list

TelepathicGrunt commented 1 year ago

Do not forget to set potion_list to [] as well. Both potion_list set to blank and harmful_potions set to false will stop the current problematic anti beacon code from running at all at cost of making the block no longer remove status effects