Every time i try to get out... It pulls me right back in!
Modding, you can check out whenever you like, but you can never leave...
Anyways, back to optimizations. I don't have as much data or have done much testing, so feel free to disregard me, but it seems like everyone has been missing another potential source for Optimization. Abilities.
While I doubt most lag is even remotely caused by abilities and buffs, anyone who has ever made a passive ability for a common unit and left the buff at "PrioritizeNewBuffs" can tell you, it can sure kill your frame rate if you do it wrong. So far I haven't seen any abilities do something wrong on that magnitude, but I think some could be quite a bit more efficient while doing the exact same thing they do now, mainly older ones that haven't been updated to use the new stuff they add in each expansion, most notably the new conditions we got in Rebellion.
For example, take the TEC Shield generator structure. This absolutely hate this ability, its so terribly written its a good thing they're not worth building, otherwise it might have caused more issues. Basically what it does is apply a buff to itself that then constantly tries to apply a periodic action every second to the local planet in case its player owned, regardless if the planet already has the buff or not. Also both buffs will end if the owner no longer has the labs for the structure, which is redundant since the planet buff will end if the shield generator buff is lost, though I'm not sure if additional finish condition checks hurt performance.
While not as bad as creating hundreds of new buffs a second, from my experience periodic actions are much more intensive than instant actions, and if you have lots of them going at once it can degrade performance. If you can possibly write an ability to intelligently use instant actions to do the exact same thing, I believe (not that I have any proof of it) that instant actions are much less intensive, as after they apply you can usually get rid of the buffs that have them. In general the only times I've seen where infinite periodic actions are absolutely needed are on passive area of effect abilities like targeting uplink or in cases where you want to simulate a weapon that can fire on multiple targets.
As a proof of concept, I have rewritten the TEC shield generator ability to use only instant actions, preventing the needed for it to apply a periodic action every second. To do this I had to make it an active ability rather than passive (this can be better since the ability can automatically only apply when they have a target available, rather than constantly trying to apply a buff via a periodic action), and create an additional buff file (which may increase RAM usage very slightly, but this buff only applies the other two buffs simultaneously then completely disappears). The end result is that you get a planet that's shielded and the buffs cancel themselves exactly like the original would, but there is no periodic action every single second checking if the buff went missing.
Note I made this for my mod and the shield is 20% more effective at all levels if you want to include this. If anyone wants to do some testing to see if this actually makes much difference even better.