• We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

Stellaris Dev Diary #170 - Performance and other technical issues

Hello, my friends! This is Moah, Tech Lead of Stellaris typing. I can finally talk about what you’ve all been waiting for: How many new platypi will there be in Federations? After weeks of…

Well, apparently, I should be "more technical." But before we jump into the mysteries of the Stellaris code, I want to take the time to talk a little about the balance between adding new features, improving performance and stability – especially in terms of multiplayer and the dreaded out-of-syncs (dreaded at least by me).

The Delicate Balance
Stellaris, like most decently sized code bases, is like a complex game of Mikado or Jenga: every part is connected in some way to every other part. When you add a feature, you add more connections. If you’re careful, you add only a few, if you’re in a rush you add a bit too many. This generally leads to Unplanned Features (aka bugs). In addition, once we see them perform in the actual game, we tend to expand features in new, unexpected ways, leading to more Unplanned Features(tm).

Once we realize what is happening, we start being more careful. Maybe too careful. Checking too many things, too often, ensuring that this interaction that is supposed to never actually happen is actually not happening. Not now, not later. Not ever.

So you have removed the unplanned features, but the game is a bit, ah… too careful. Some would say slow.

So you remove some of these checks. You realize that you don’t need to loop around the galaxy, you can just loop around this one tiny planet. Then you go one step further, and think “well I can maybe do that check only every three weeks, and this calculation needed by all these checks, I could store it in here and reuse it until the next time it changes.”

So now the game isn’t so careful anymore, we’re back in unplanned feature territory. But if the caching (storing/reusing calculations) happens at different times on different machines, you get slightly different results (like asking a developer for something before and after they had coffee).

Slightly different results are what OOS thrives on! Clients and servers have 0.0001 cost difference, compounded over time, that corvette is bought on the server but not on the client.

So you remove your “smart” algorithm. You replace it with the correct algorithm. You lose half of what you gained in step 2 and reintroduce some bugs. Probably.
Rinse and repeat.

But enough about my morning routine! Let’s talk about…

Performance
Stellaris fans are like C++ programmers: performance is always on their mind. To be fair, it has also been on ours a lot lately. We know that it’s not all that it could be, especially in late game and with the bigger galaxies. With that in mind, we’ve taken time to improve performance in a bit more depth than we usually can. We looked at what was taking the most time, and as everyone knows that is…

G3Zg2ENmwufWgqUXGFjTEebkxlbQzYRGI0diuSOCrFfUcSl9Xn8EkYCyzAUtWAyCdVXt5biT3vv65T4n-EnA5YmHZXb_Gpp9ydvqh28lj_Oa7py3yU3MHETwURjuo1QD4sFZiZNB


Pops.

There are many reasons why pops consume a lot of time in Stellaris, but the main one is that by endgame we have SO MANY of them. SO So so so so many. And they do so much! Pops have to calculate how good they’d be at every job (they do so every 7 days). Then they have to fight every other pop on the planet to get the job they’re best at. They also have to check if they could have a specific ethic. If they could join a specific faction. How happy they are. How happy they could be. How happy they would be on that planet over there.
All these things trigger modifiers calculations. If you remember my last dev diary, you know that modifiers are the only thing more numerous than Pops in Stellaris. And they all depend on each other. Calculating them is like pulling on a thread and getting the whole sweater.


OK, but what did we actually do about it?
Well first, I’ll admit I may have been a bit pigheaded on the whole “we need to do the jobs distribution every day because we don’t know when new jobs are added.” We reexamined this assumption, and jobs distribution is now only done on demand. It was also rewritten to iterate over a lot fewer things.

We also noticed a few triggers going through every pop of an empire to check if one or more are enslaved, decadent, or other things that can be tested at the species level. So we made new triggers to test these things at the species levels. In the same spirit, we had events going through every ship to find a fleet, so we added triggers at the fleet level.

Second, We’ve also reworked the approach to checking if pops can change ethics (and also made it work again), or if they can join factions.

Finally, we’ve looked for (and found) opportunities to use more multi threading.

But enough talk! What’s the result? Well, if a picture is worth a thousand words, here’s the answer at 30000 words a second:


The video compares the performance of 2.5.1 “Shelley” to 2.6 “Verne'' when running a save game from the community, which can be found attached to this post, with over 20000 pops. It was recorded on my work computer (Intel Core7-7900X @ 3.30Ghz, 10 cores and 20 threads, and AMD R9 Fury). You won’t necessarily get the same results, the exact difference in performance will vary with your computer, and the exact situation in your own save games, of course. On average, we’ve found something between 15% and 30% improvement in late game situations.
This save is just ideal to showcase the impact of the pops improvement.

DYxcPB_pqZfHKxxtAj0sh_Y3nx7zXM4OMcUHTkgNsDK9csuQgEECkgc6jVmUEgWpoa6lD2e9kfYdssD61j2I57mhM0XcyT20wfu8fFIZbP-Usqnw2PShuEAD0_-n-ZTNFcH0NJR6


What is this average anyway? How do you know?
Well, we have synths playing the game all night, every night. In the morning, we check how far they were able to go. We also ask them how many errors they encountered, what their endgame looked like, whether they got any OOS and then put all of that in tables and graphs, with many colors. Then we wipe the synths, so they don’t ask pesky questions about souls and whatnot.

EwNw1Mhvr5FLcwYQYuZClsoMxr8qHs3nF3VPqExEcAJrWCvISTEc2fcl3fNLWzQlWKdxuDLAGHEagL9FXOrtio6XazmKpx_rsR7Ri58Ts2tFbq7OcWPdsIG_ayumIutkMGm2VnD_


In conclusion
Although we keep performance in mind and do our best to keep it reasonable, we’re happy we had a chance to take a deeper dive into the issue. Hopefully the changes will spark as much joy for you as it did for us, and we’re looking forward to your feedback!

Next week will feature another dev diary about the other thing you’ve all been waiting for… MORE PLATYPI!

PS: The save file we're using is from the community, one of the performance threads. We are however unsure where we originally got it from. So if you recognize it, or if it's yours please tell us so we can credit you properly.
 

Attachments

  • perf_massive.sav
    4 MB · Views: 289
Last edited:
  • 1Like
Reactions:
Is there any plan to address the fact xenocompatibilty spawns infinite species, or the fact that the AI Gene mods so many templates into existence the colonization screen and species screen can become unstable?
 
Thats my impression, too. Its strange, that an issue, which showed up when? Two years ago? was only adressed, when the complains went up to an level, which could not be longer ignored. I assumed, it was mostly, because sales dropped down or something like this. Even the game testing magazines have began to write this issues in their reports. Paradox seemed to changed into an company, which throws out games, which are nice at the early part of a game, because only this parts are really tested. And the rest is ignored. The endgame is still buggy. I would bet good money, that there will be several dlcs before this issue will be adressed. If they adress it at all.


I'm not sure of how or why but I would ASSUME that Paradox realized that there would be a net positive [long term?] ROI to at least address performance which has been an issue for about 15 months. I know that a fix to performance [and releasing an otherwise solid DLC] would prompt me to purchase again. I know my purchase means NOTHING in isolation but it's my way of rewarding Paradox for doing what I want.

If I was a betting man I would think that AI will never be "permanently fixed" per-se because each new, major DLC / gameplay update will likely require some or even a lot of AI updates. Still it's likely that at least improvements to the "economic AI" will show themselves before long -- maybe before FEDERATIONS launches.

As for the rest of the things I want [Fixes to Crisis, Awakened Empires, balance ...] I'm not sure if they will EVER be addressed. Not because they aren't broken but there's not enough people that care enough to justify Paradox spending more than trivial time & effort fixing those things.


Nevertheless, regarding the increasing population problem: my five cents of ideas would be in an direction, which i doubt that many like: <SNIP>

I'd rather fix the increasing population problem differently. Effectively I'd like to change the fundamental systems involved so we don't necessarily track and simulate every single individual POP across the whole galaxy daily [or even monthly]. If new systems can be created to relieve both the MICRO and PERFORMANCE burden I would certainly be happier esp. if these [boring?] game elements could be replaced by something more interesting -- like Diplomacy, Espionage, ...
 
Is there any plan to address the fact xenocompatibilty spawns infinite species, or the fact that the AI Gene mods so many templates into existence the colonization screen and species screen can become unstable?

I hope so. That's something [if possible] I'm tempted to MOD ... I.E. not let the AI get Xeno Compatibility to start with. While you can't mode AI gene-template behavior I'd be happy enough if the AI can't use the tools properly that you take the tools away until they can use them.
 
Is there any plan to address the fact xenocompatibilty spawns infinite species, or the fact that the AI Gene mods so many templates into existence the colonization screen and species screen can become unstable?

Moah said that there wasn't any plans to do this in the stream.
 
I was hyped and planned to buy the expansion because of the performance focus on the patch, but they basically did what a Russian mod with short description did long ago I think that mod has 30% on it too unfortunately I cant pour money in another expansion that I can play only for a couple of hours and restart and max I play is medium galaxy ( a year ago I got a laptop just for this game recommended specs from this forum) , last week I jumped in to a game with small galaxy got to the crisis date finally only to see they weren't moving cause they needed to invade a planet with 0 defences first...
 
Would it be at all possible to add an option to disable automatically assigning pops to jobs in order to reduce system load? If my impression of this article is correct, since a lot of processing power in later game gets devoted to calculating pop management, adding an opt-in feature to manually manage pops would free up a lot of resources for larger games, especially on the multiplayer end. I wouldn't mind dealing with pop micro-management again if it resulted in significant performance increases.
 
What is this average anyway? How do you know?
Well, we have synths playing the game all night, every night. In the morning, we check how far they were able to go. We also ask them how many errors they encountered, what their endgame looked like, whether they got any OOS and then put all of that in tables and graphs, with many colors. Then we wipe the synths, so they don’t ask pesky questions about souls and whatnot.

egfuqW9.png
 
Would it be at all possible to add an option to disable automatically assigning pops to jobs in order to reduce system load? If my impression of this article is correct, since a lot of processing power in later game gets devoted to calculating pop management, adding an opt-in feature to manually manage pops would free up a lot of resources for larger games, especially on the multiplayer end. I wouldn't mind dealing with pop micro-management again if it resulted in significant performance increases.

I wouldn't mind that as almost a "hidden" option but I'd RATHER have system-wide fixes to both mitigate the performance impact AND the micro impact of running larger empires.
 
This is not a criticism because this is not what the point of this dev diary was about but I do think there is an intrinsic flaw with population always increasing and never substantially decreasing. Now there may be balance reasons for that but I do think simply having more mechanisms for populations to decline or level off would be very good for the game.

The way pops 'decline' one at a time doesn't really allow the population to decrease suddenly, even with an 'Extermination' purge; if you want to fix the overall demographics of Stellaris, I would start here. Just like empires can assimilate several pops at once, it should be possible for several pops to die at once on the same planet, and as a genocidal empire, you shouldn't be able to keep Forced Labour etc pops alive for decades by herding them onto a 'purge world'.
 
A possible solution to your performance problem is to add an abstraction layers to population. You can abstract pop changes to be by building then a planet-wide abstraction level. Each tier identifies changes that can be bubbled up to the higher abstraction level in which each reduces the interaction at the tic level. It is a well used technique for AI software.

I forgot to mention that those planet-wide changes be classified so you can have them run as a separate process that feeds back down the layers to effect the population. (e.g. pop planet purge is identified and that spawns a process that feeds back through the abstraction layers to eliminate the population per determined time duration). In this way you no longer tie population checks to individual time tics.
 
Last edited:
Personally the only DLC I haven't bought was the Lithoids species pack and that was purely due to the fact that I was shocked to see that nothing had been done regarding performance around Ancient Relics which was in itself a good DLC.

Let's be honest a playthrough with the intention of winning or at least getting to the endgame crisis is maybe 1\2 days real time. So the frustration of investing 10\20 hours in a game once after a patch only having to give up due to the broken performance and then again after another patch (and 20€ paid on a DLC you can't experience to the full) is maddening.

I will wait until the new patch\DLC comes out and then periodically check on these forums to see if the game is fixed before buying any more DLC.

Also I have said this on the performance forums and I will say it again and for the last time, If the performance optimisation is complete it should be released immediately as a Beta to everyone who wishes to try it. This is not a "free update with new content" this is an urgent fix for something that has made a game which we have invested time and a fair amount of money unplayable in mid to late game for over a year now while numerous paid DLC's have been churned out.

On a lighter note: Thank you for explaining in detail, and quite amusingly the problems and what you are doing to try to fix them. I feel a little hope that I will be able to return to this game in the future.
 
Increased tech cost + reduced habitable worlds + max amount AIs have kind a no xenocompatibility in game effect, AIs just don't get to the 8 ascension perk and XC probably has a very low weight, so they never get to pick it.
 
Would it be at all possible to add an option to disable automatically assigning pops to jobs in order to reduce system load?

X number of AI opponents are still doing it automatically.

adding an opt-in feature to manually manage pops would free up a lot of resources for larger games, especially on the multiplayer end.

Nevermind. Need more coffee. Sorry. In context this time. Yes, multiplayer, that's not a bad idea, although disabling automation like that when you can't be pausing the game, is going to make finding anyone willing to micro-manage to that level in a competition, difficult.
 
Last edited:
Moah said:
Although we calculate how good a pop is at every job every seven day, we redistribute pops to jobs (or jobs to pops) every day.

Why? Job redistribution should only occur on change of traits, creation of jobs, destruction of jobs, change of pop's faction, change of faction happiness, creation of pops, destruction of pops, movement of pops, change of species rights, change of policies, and conquest. Things such as the +20% miner production tech doesn't change who is going to be a miner. Planet-wide, empire-wide, job-wide, and most species-wide changes to production shouldn't trigger a job reshuffle.
 
Why? Job redistribution should only occur on change of traits, creation of jobs, destruction of jobs, change of pop's faction, change of faction happiness, creation of pops, destruction of pops, movement of pops, change of species rights, change of policies, and conquest. Things such as the +20% miner production tech doesn't change who is going to be a miner. Planet-wide, empire-wide, job-wide, and most species-wide changes to production shouldn't trigger a job reshuffle.

Because the original coding of the feature was rushed for a Christmas release (IMO), and it's only now that Moah and co. have had time to re-visit the feature in order to optimise it for better performance. That's why. If you read the rest of the OP's DD, it's pretty clear that Moah is aware of the better approach you describe, and is doing exactly that.

Well first, I’ll admit I may have been a bit pigheaded on the whole “we need to do the jobs distribution every day because we don’t know when new jobs are added.” We reexamined this assumption, and jobs distribution is now only done on demand. It was also rewritten to iterate over a lot fewer things.

He's even humble about it. There's quite a few dwellers of the Performance Megathread (including myself) going "well duh", of course, so I think many of us share your frustration, but it's finally being addressed.
 
Last edited:
This is a long thread so if someone has mentioned this please forgive... anyway no mention of the AI's building but not settling of Habitats. I remember reading that they are also causing some of the performance issue, is there a way to fix this?
 
This is a long thread so if someone has mentioned this please forgive... anyway no mention of the AI's building but not settling of Habitats. I remember reading that they are also causing some of the performance issue, is there a way to fix this?

Next week's dev diary should be addressing AI, apparently it was mentioned on the stream.