team-abnormals / blueprint

Library that implements the framework of all Abnormals mods
https://www.curseforge.com/minecraft/mc-mods/blueprint
Other
111 stars 34 forks source link

[1.16] High CPU usage for TrackedEntityMixin #133

Closed nthxny closed 2 years ago

nthxny commented 2 years ago

hey, noticed something with Abnormals Core while doing perf testing on my modpack, the TrackedEntity mixin from abnormals core is taking a while to post over the Forge event bus. Currently sitting at ~4% of my total tick times while flying around the world. Not sure what is going on with it as it seems it's just EventBus.post causing the lag, and not your consumer.

Does this need to go over the event bus anyway? AFAIK this is just consumed and handled internally, is anyone depending on this event themselves?

image

https://spark.lucko.me/tFWLf88jQz

SmellyModder commented 2 years ago

The performance percentages for TrackedEntity in that spark viewer likely come from the number of TrackedEntity instances getting ticked on your server.

After doing some performance tests using spark on my own, I found that TrackedEntity#tick() rarely even went over 1% CPU usage on servers. As more entities get ticked on your server, you will see the CPU usage of TrackedEntity#tick() begin to rise.

However, with all this said, the issue is still not answered. TrackedEntity#tick() will often not consume over 1% CPU percentage because many of its internal processes only happen every once in a while per entity and are not too expensive when they do happen.

Notice how there is a significant CPU usage difference between TrackedEntity#handler$bge006$tick() and TrackedEntity#handler$bge000$update(). This difference is explained by the frequency of when these methods are processed, with $tick() running every tick and $update() running only when a TrackedEntity updates its entity's motion.

With all this considered, removing the firing of these events would likely improve the CPU performance of TrackedEntity#tick() but probably not be noticeable in game. This change will have to come in 1.17 because we cannot assume no mod is currently making use of EntityTrackingEvent.