[1.16.5] Extreme lag from Tree Felling Demon
NielsPilgaard opened this issue ยท 7 comments
Describe the bug
After spawning an Occultist demon that handles tree felling and the cleaning up of said trees the server suffered massive tickrate issues and caused everything else to slow down when the chunk he was in was loaded, even crashing the server on multiple occasions.
After inspecting the spark log I discovered this and killed the demon which completely fixed the issue.
To Reproduce
Steps to reproduce the behavior:
- See description :)
Expected behavior
Far less lag
System (please complete the following information):
- Occultism Version: 1.16.5-1.0.15
- OS: [e.g. Windows] Not sure
- Minecraft Version: 1.16.5
- Modpack Link and Version, or list of mods: Enigmatica 6 v0.4.3
Additional context
EnigmaticaModpacks/Enigmatica6#1680
Another thing that may work as well is skipping the issue entirely and just make an "Othersoil" that works like dirt and allows saplings to be planted on it and then have the lumberjack only chop trees with that block below them.
Good find .. but this is a tough one. In essence, this comes down to the good old "lumberaxe problem" and the performance issues that come with it at times, except the tree detection needs to happen whenever a new AI goal is selected, in order to even identify a tree. I'll see what can be improved here
For the time being that one, I believe, needs to be iceboxed. There really is no way around detecting a tree in order to walk to it, and the detection is tough on performance as it has to verify various parameters to avoid cutting down wooden houses.
Open to suggestions to simplify tree detection though - or pointers towards other mods that have tree felling AI that does it better!
MineColonies has entities looking for trees that don't cause lag spikes, at least not any reported ones afaik.
It's using GPL3 license though so perhaps it's better to ask their devs for advice rather than look at the code, but here's the link anyways: https://github.com/ldtteam/minecolonies
One thing to note is that they confirm it being a tree by checking if it's a block that allows a sapling to grow under the bottommost logs, if it's not then they assume it's intended to remain. That part is mentioned in the documentation as you can use that to have them skip some trees in their area by replacing the dirt with cobble underneath it.
I haven't checked, but from your description it sounds like you're performing the search for available trees in a single tick, if that's the case then you could probably just solve your issues by running the search over several ticks so that there isn't a spike, even without any other changes to the algorithm.
@Sylfa I initially used that approach in my experiments, but decided it was too dangerous to accidentally target a building. But it's worth considering for targeting, and then use the existing logic for felling.
As for spreading the algo over multiple ticks, that is definitely an option, but it's not trivial to avoid "locking" the ai. With more time at hands that is a safe option to implement.
Thank you for your input - it's given me some food for thought to get this out of the way eventually