Hi,
This mod has been amazing. Combined with Rampant AI, I've had one of the most intense MP games of factorio ever. It's the first time I've fully lost an outpost in literally hundreds of hours of playing.
However, late game we started noticing some pretty hefty slowdown when facing bigger waves. At first we figured it was just something that would be unavoidable with so many biters about, but eventually noticed it only occurs when Leech Spitters take damage.
I took a look at the code and noticed that moveLeechDrain() is called every time a leech spitter takes damage. The for loop that runs in it totally kills performance. For a big attack wave, it can go from 60UPS to < 10UPS.
Removing the moveLeechDrain() function call in onDamage totally removes the slowdown.
We also noticed that after the very early game, we never really noticed the spitter leech effects. It was only after taking a look at the code I realised why - the drain entity is always placed on the spitter position - which will almost always be outside of the electricity grid of the factory once you have a wall and turrets up.
So, I made a custom change in an attempt to fix both of these issues:
-
The leech entity is now spawned using the getTunnelPos() function. This will spawn the entity somewhere inside the factory walls, and hopefully somewhere it can do the leeching intended. I think of it more like the leech spitter is using a ranged electrical drain attack.
-
Since we aren't moving the entity to be on the same position as the spitter anymore, deleting and moving it every frame isn't necessary. So I've moved the for loop to destroy the entity into the onDie() function. So now the drain entities created by the spitter will die when it does.
This saves an absolute ton of performance. Most of the time the UPS doesn't budge much from 60, and the lowest we have seen it drop is 45 UPS. And the changes are stable so far, no apparent bugs have arisen from the change.
And, as a bonus, the leech effects are working a lot more regularly - and are pretty potent!
A further small tweak was to roughly double the range on getTunnelPos(), just to make sure drain entities reached inside the walls.
If you're interested I'll upload the changes somewhere.