abluescarab / tModLoader-WingSlot

This mod adds a dedicated wing slot to the inventory.
GNU General Public License v3.0
16 stars 9 forks source link

WingSlotPlayer.Initialize() seems to be called every game tick on multiplayer #14

Closed Mourdraug closed 6 years ago

Mourdraug commented 6 years ago

I recently started new playthrough with multiple mods and ran into performance issues, singleplayer was perfectly smooth, but multiplayer was performing worse on every client, especially noticable on AMD cpus which have worse per-thread performance.

So I poked around with profiler and noticed that in multiplayer on clientClone() method invoked from Terraria doUpdate() on main thread (it's only called on multiplayer client) where mod loader hooks with its ModPlayer.createFor method, where to my surprise I saw only one call with noticable performance: WingSlotPlayer.Initialize() which takes ~16% of thread time. That's a lot considering that main thread has to do all tick updates and rendering. Screenshot from profiler overview

Note though, that I never done any terraria mod development, so I don't know if it's intended to run on every tick. But since method is called "Initialize" I'd say it's not.

EDIT: After some more digging I found out that this is not such big issue when there are only few mods that don't add so many items, because Item.SetDefaults() takes more time the more recipes you have registered, up to some absurd values(it's prob vanilla flaw). Setting noMatCheck argument to true seems to be a workaround.

abluescarab commented 6 years ago

Fixed by 9fc28b7.