More Naval AI Profiling

So.
I don't know much about coding.
However I can tell you 2 things:
1) IIRC, RifE is not really quicker than MnAI. I'm not sure you'll find ideas there.

2) I propose that you look into the MoM code.
last christmas, Sephi released a new alpha version which is way quicker than former versions 1.42 (both on load time, interturn and civilopedia access).
you might get some ideas by comparing the codes.
however note that MoM alpha changes many mechanic as compared to MoM 1.42 which itself also has many mechanics very different from MnAI .

However there is IMO more chances to find solutions to FFH related issues here than in completly unrelated mods.
 
So.
I don't know much about coding.
However I can tell you 2 things:
1) IIRC, RifE is not really quicker than MnAI. I'm not sure you'll find ideas there.

Please note that I have not done any performance tests in RifE (in fact, I have not played it enough to get a feeling of how fast or slow it runs compared against MNAI), but even if RifE as a whole is slower than MNAI that does not mean that all of RifE components are slower than MNAI; some may be slower and some may be faster. Besides that, in computer programs the speed of the program does not depend only in the code itself. It is also important (and usually way more important) the number of data elements to process.

This means that since RifE has a lot more different game elements than MNAI (more spells, more civilizations, more unit classes and so on), RifE is of course going to be more slow than MNAI if we assumed that they could use the same source code. We cannot assume that RifE source code is slower just because the results are slower.

In the spell case, which I mentioned earlier, RifE and MNAI are quite similar. RifE may have additional spell prerrequisites to take into account, but the canCast code is quite similar except for Snarko's performance changes and RifE specific stuff. Since that specific change improved RifE performance, it should also help MNAI performance if it were ported. Since MNAI has less spells, the performance impact would be smaller than in RifE, but since both mods have roughly the same mechanics for spells we would have an improvement nonetheless.

2) I propose that you look into the MoM code.
last christmas, Sephi released a new alpha version which is way quicker than former versions 1.42 (both on load time, interturn and civilopedia access).
you might get some ideas by comparing the codes.
however note that MoM alpha changes many mechanic as compared to MoM 1.42 which itself also has many mechanics very different from MnAI .

However there is IMO more chances to find solutions to FFH related issues here than in completly unrelated mods.

I think that you are overestimating the source code differences between mods. The XML and python parts of mods are vastly different, but the DLL code is quite similar. As long as the performance issues are not directly related to FFH specific features such as spells, most of the performance improvements made in any mod could be adapted to work in MNAI.

What you mention about MoM is very interesting, but I would need more specific pointers to know what parts of the source code I should check. In the distant future, when I'm done with my current proposal and checking K-Mod changes, I'll try to check MoM source code to see if we can find any ideas for improvement. I saw some notes about performance in their commit log.

As a general note, I would also like to mention that for solving performance issues just picking up performance changes from other mods is IMO not the best idea. I think that it is far better to profile MNAI itself, analyze any performance issues that we can find, and then think about possible fixes for the specific MNAI issues. When this point is reached, it is time to check other mods to see if they have solved that particular problem. Once that all obvious performance chokepoints are found, it may be worth the effort to look into general, less specific fixes from other mods that make the source code faster as a whole.
 
You know better than me how to do it.
I was just pointing at the 1 mod I know that brutally improved it's own speed while maintaining the same "outward" complexity (as felt by a non-coding player).
 
I managed to find the underlying issue in the AI_unitValue method. Most of its cost actually comes from calling the AI_combatValue and AI_trueCombatValue methods. Therefore, I have created a cache for each one of these values that gets cleared as less frequently as possible. Since these methods are also called from many other places besides AI_unitValue, the new cache should also improve speed in parts of the code that are not being measured.

If I were to attribute all of the differences in speed to my changes, it would mean that after this change turns take just 65% of their previous time (this has been calculated by taking into account all turns except the one with the smallest value from each log, which was significantly smaller than the others for some reason). Given how imprecise the profiling can be and that the conditions under which I took the measures are not normal conditions because they were chosen to minimize the impact in performance of stuff not related to the DLL (sound off, window with a resolution as small as possible, all graphical options set to minimum, game run on automation with the game minimized) I don't think that the improvement will be this big in normal games. I'm hoping that it should still be noticeable, though.

I'm uploading a MNAI 2.42 dll that includes my performance changes. If you are interested, give it some testing and report your feedback here. I'm specially interested on knowing if it makes the AI act weird in any way (which would mean that my cache change has errors) and if the game feels faster (specially in the late game). I'm unable to test on multiplayer at the moment, so I would appreciate a multiplayer test to see if my changes create any OOS errors. I'm also uploading the "before" and "after" profile logs, the savegame and the source code in a different file.

Edit: Don't forget to backup the dll before overwriting it with this one!
 

Attachments

[to_xp]Gekko;12233871 said:
that's pretty sweet! I'll let you know if I notice wacky AI .

Thanks :)

I have run some test games without problems and without noticing any strange behavior in the AI. I have also checked other mods to see if they have done something similar without finding anything (I'm not able to find the source code repository of MoM, though).
 
Back
Top Bottom