SuperMartijn642 / MovingElevators

19 stars 15 forks source link

[Bug] Severe periodic stuttering apparently due to setRemoved() call taking a huge amount of time #135

Closed glindsey closed 1 year ago

glindsey commented 2 years ago

Version Info

Are you using OptiFine?: no

Description of the Bug Stutters in entity ticks seem to occur roughly every second. Using the Spark profiler seems to point to com.supermartijn642.movingelevators.blocks.RemoteControllerBlockEntity.setRemoved(), which is consuming almost 82% of CPU resources. The profile can be found here: [https://spark.lucko.me/JCVxxSasGa] (I don't know how long Spark keeps profiler links available, but hopefully it'll still be accessible by you.)

Overall TPS remains okay, so it looks like it's just one tick every once in a while that takes a ton of time. Garbage collection, maybe?

Steps to Reproduce I have a 6x6x4 elevator at my base, with seven or eight floors. Each floor has an elevator controller, as well as a remote controller attached to it. I only noticed the issue once I left the base to go exploring, but it may very well have been happening at the base as well, and I just didn't realize it because there were no creatures around.

I do have a ton of mods on this server, but the profiler results don't seem to suggest any of them as culprits. Still, I'll try to test things out with only Moving Elevators on its own world if I get the chance.

Unfortunately, as I was trying to investigate this bug further, the Mojang auth servers decided to go down at exactly the wrong time. I'm submitting this bug anyway, as I don't think it's related to the auth issues. When the auth servers come back up I'll try to investigate further.

glindsey commented 2 years ago

Update: The problem does not occur when I am near the elevator, as per this profiler result; it does occur if I am 500 blocks away or 1000 blocks away.

I forgot to mention I'm running the server and client on separate computers; the profiler is running on the server. The client does not appear to be affected.

glindsey commented 2 years ago

Okay, I just tested the same thing on a superflat world with only Moving Elevators and Spark installed, and the problem isn't occurring -- it looks like setRemoved() is never called. Some other mod must be causing it to fire off a bunch of times when it shouldn't be.

SuperMartijn642 commented 2 years ago

Looking at your first Spark log, it seems like a remote controller entity is being removed and during that it's trying to load the controller entity it's bound to. Not entirely sure why that would take up that much performance. The BlockEntity#setRemoved() method is called when the associated block is broken or simply when the chunk the entity is in gets unloaded.

The Spark log from your second message doesn't seem to have significant performance taken up by Moving Elevators.

I've changed the way the remote elevator panels query an elevator group to bypass the need to load the controller entity they're bound to. Hopefully this will help with performance. The changes are available in Moving Elevators 1.3.8 for all versions.

Thank you for your effort so far and let me know if the 1.3.8 update makes any difference 🙂