There’s a couple of bugs in Stellaris, that have been present for year(s), where the AI inexplicably builds absurd numbers of construction and/or science ships, then has them sit idle forever.
This AI behaviour would be merely eccentric if it didn’t cause major performance issues with the game.
For the case of too many science ships, the effect seems subtle – just a small, evenly-spread slow-down of the game. Probably not worth worrying about generally, though if you happen to notice an AI empire spamming science ships, it may be worth addressing.
For the case of too many construction ships, the effect is much more pronounced. Every AI construction ship triggers an expensive script periodically, and all aligned together in time, which can result in noticeable hangs every seven in-game days if there’s many of them.
And “too many” is a surprisingly small number – as few as ten can cause five-second-long hangs every seven in-game days, in my experience. I suspect their detrimental effect is superlinear to their number (because the AI having only a couple seems to incur no noticeable overhead). It’s likely also contingent on some other factor, that I have not yet identified, as the hangs only manifest themselves in some games.
I’m very thankful to Confident_Chance_770 for pinning the periodic hangs down to this cause.
Confirming the too-many-construction-ships diagnosis
Since this can be caused by a mere few construction ships – as little as four or five, which is not otherwise remarkable – one way to confirm this is the issue is to profile the game’s script execution:
- Pause the game (e.g. hit the spacebar). Ideally a day or so before the next hang day, and clear of the first day of the in-game month.
- Hit the backtick (`) key (top-left on most keyboard layouts, above tab and left of 1) to bring up the game’s debugger / cheat console.
- Type “script_profiler” and hit return.
- Unpause the game (e.g. close the console by hitting the backtick key again, then hit the spacebar).
- Let the game run until one of the hang days is encountered. Note that the game will run slower than normal while profiling is enabled, especially on the hang days.
- Pause the game.
- Open the console again.
- Type “script_profiler” again and hit return. This concludes the profiling and dumps the results to two files.
- Open the summary results from ~/Documents/Paradox Interactive/Stellaris/logs/script_profiling_summary.log.
- Check if “planet_possible.find_planet” is the topmost item and listed as consuming significant amounts of CPU time (e.g. 5s, for a single hang day). If it is, you’re likely experiencing the construction ship bug.
If it’s not, it’s possible it’s still the same bug, but possibly not. You could try the usual diagnostic routine – e.g. websearch for the symptoms and top script names from the profile, contact the author of any suspicious or newly-added plug-ins you’re using, contact Paradox Interactive, etc.
Remedying the bugs
If you determine that it likely is the construction / science ship spam bug, you can rectify it via these steps:
- Save your game. Just in case something goes wrong with this process.
- Pause the game. This is very important – if you don’t, the AI is likely to complete screw with your empire while you’re away (during steps 4 through 6).
- Open the console.
- Type “play N” where N is an integer starting at one. Not all integers are used – just keep incrementing until you get a correct result, which is that it switches your control to one of the AI empires.
- Close the console.
- Check the civilian ships list to see if there are absurd numbers of science ships, or more than a couple of construction ships. If there are, kill them. Usually when this bug occurs most of the ships are together in one system, so you can accelerate this process by finding those big group(s) of construction & science ships, drag-selecting them within the system view, then hitting the Delete key (and return to confirm decommissioning). It’s pretty safe to just delete all the AI empire’s construction & science ships, since the AI can cheaply and quickly build new ones if they actually want them (in my experience they often don’t, at least not promptly, suggesting the ships were unnecessary to begin with).
If there are not, go back to step 4 and try subsequent integers, to check other AI empires. - Once you’ve found and destroyed the offending ships, type “play 0” into the console to restore control to your own empire.
- Unpause the game and continue playing – hopefully now without the noticeable hangs every seven in-game days.
Repeat as necessary when the problem recurs (and perhaps focus your in-game efforts on wiping out the offending AIs, as a more permanent solution).