• 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:
In continuation to previous comment

Since I do not really think that any amount of optimisation of pops will actually satisfy everyone (frankly, I do not see much of difference if people who find 2k pops unbearable now will find 2.5k pops unbearable after the team has put another 6 month of work into improvements), I tend to agree that the only way to solve this for people who like to play into the 2700s is to introduce some mechanism of getting rid of extra population.

Hard limit on the amount of pops in the empire that will split it in half and make halves genocidal towards each other might work, but players generally do not like when something hard earned is taken away from them. It applies to other possible disasters too.

One possible way was described in a previous post: converting pops/growth to effectiveness or inflating the pops if you will.

Another one, I want to describe shortly is based on the missed opportunity of the arcologies. You see, arcology in general is a big self-sustaining building, it has nothing to do with ecumenopolis, because world filled with arcologies will not be an ecumenopolis (see Isaac Arthur's videos on them, if you need clarification).

So, since arcology can be understood as a self sustaining big building, it can be introduced into a game like a special planet building / decision. In my initial view it can take 4 building slots (i.e. occupy a row of buildings in the planetary interface). It has a starting capacity of 20-40 pops, which probably can be improved by a repeatable tech. It can produce all sorts of things like research, minerals, alloys, trade, food, energy in small amounts, equal per number of residents and its residents do not consume anything produced outside. The population in it is not switching ethics or jobs, they all have the same job (and you can make singe ethics arcologies, make xenophobic arcology for example) and they can only leave the arcology once a year (or at least you do not have to roll the chance for every resident, just once for the whole arcology), so no need to calculate them often. It can be a lore-appropriate effective way of "dumping excess population" out of the recalculation loops.

Implementations may wary, like in the most minimal variant, arcology may just produce fixed amount of trade. Or it may produce a little bit of everything (really little, like 0.01 rare resource per resident). In rich variant, you may go for different upgrades/specialisations (Though I really think it should be closer to fire and forget than to here is another tamagochi for you kind of thing). It may have an upgradable carrying capacity through sociology repeatable (in which case its basically a bottomless well for pops) or it may have upgradable production capacity through engineering repeatable. It can also cost a lot to construct, comparable to a habitat. And demolishing/constructing it can be a lengthy (3-5 years) process to lessen the amount of started+cancelled=useless recalculations. As an extreme variant it may be a transformation upgrade for ring segments/habitats/planets -- press one button to reduce a rich living world to a simple +x resources per month with practically zero calculations.

P.S. Again, laziest way with arcologies, take all energy produced by pops per year, divided by number of pops, make all pops in arcologies produce that amount of energy per pop for the next year. Repeat for all other resources produced by jobs. It will immediately incentivise to have only say one research world and work maximising that. Abusable? Like hell. But beyond 300 years or 5k pops why does it matter. The game has already been won by every metric possible. It is just stacking numbers for bragging rights anyway. :)

P.P.S. Or make it a next level. Galaxy reaches X pops, event fired: star cluster in the core is going to explode in 20 years and sterilise the galaxy (variant: will kill 99% of population). Either build a ship to colonise the neighbouring galaxy (fleet arrives heavily damaged, computers lost, people killed, start over with 2 pops left and some random tech saved, plus your difficulty settings have been raised one step further). Or continue to play in this galaxy, but all empires will be shattered, most worlds rendered barren, again technology lost, etc. Practically mass effect effect. :)
 
Last edited:
Sounds AWESOME, thank you for tackling this issue. There's still room for improvement, but I will take an imperfect solution over no solution at all, so then again, thanks.

Also, yep, quite noticeable lag when opening a planet screen. I always wondered if fixed sectors, complete with a sector interface would help with this kind of slowdowns and micromanagement.

And last but not least: DDs are pinned topics now? WTF, I only noticed it now.
 
I'd like the devs to consider mid and late game repeatable disasters around pops dying: either nanite disasters, plagues (think alien xenomorphs getting loose), or straight microbial disease.

The idea of stable pop growth to the moon should be stripped or greatly reduced from the game now that the empty jobs don't check pops. This is going back to my post and article on performance, that would also add some more depth.
 
But will it help with stuttering issues? I wasn't able to play Stellaris since MegaCorp release. (14+ Months) on an extremely powerful rig. People have issues in mid-late game. Hold my beer, it's unplayable for me right from the start =) I will wait for 2.6.0, hopefully it will change
 
Also, if my understanding is correct (which it probably is not), if every pop participates in an endless competition for every job, why not introduce something like a flag "best guy for this job" and set it for any pop that has 100% habitability on this planet and traits, that are maximum across the empire for this job? Then ignore this pop and this job for the subsequent employment calculations. Late game, when traits and habitability modifiers are maxed, it might be helpful. Throw in some empire wide policy for automatic resettlement (to get best guys to get the best jobs) with a budget limited to the net income, if the amount of energy in storage is above 50% and this will probably result in less competition calculations. Heck you can add a preferred job option to the species screen, so player will have control over who gets to waste his energy on resettlement.
 
Last edited:
But will it help with stuttering issues?
I'm not sure if it will help you, but in my case nuking NVIDIA drivers with some 3rd party tool and then reinstalling them solved microfreezes issues both for Stellaris and another game.
 
i made my own mod for experimentation. Ship cost was doubled and fleet size halved. Military stations were more powerfull and base pop growth was cut to 1/3 without adjusting job yield (but with higher staring pop so that you would not have to wait for your first real step outside your system). It was quite nice I have to say but I would not be so bold to say it was a better way of playing. Also that did make an early conquest of a homeworld, even a primitive one very unbalanced. still, it did not feel so bad that i would totally exclude reducing pop numbers and growth from the solution. As others said. It is abstract anyway.
Maybe you also could add something like "super" pops... 1 super pop is 10 pops... a super pop can be part of 2 factions or 3. Just brainstorming here...because even if we feel somewhat connected to our first 50 pops (and I doubt that), who even knows and cares by the endgame what his empire is made of?
 
It's sticky.
 
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.
 
Pops have to calculate how good they’d be at every job (they do so every 7 days).

Why though?
Is there an actual NEED to check every 7 days, opposed to every time there is a change in pops?
Would it not be more effective to run the check only if a pop (or a job) got added/removed from a planet? after all, if you have the same pop and same jobs, the job distribution should stay the same, no?
And I don't think anyone reaches a point where the pop count and/or job list of a given planet changes more than once every 7 days (except when using resettlement probably. that could cause issues, but if resettlement is ordered to run a "delayed check" of sorts, only checking after a few days without a resettle, that could solve that issue)
 
i made my own mod for experimentation. Ship cost was doubled and fleet size halved. Military stations were more powerfull and base pop growth was cut to 1/3 without adjusting job yield (but with higher staring pop so that you would not have to wait for your first real step outside your system). It was quite nice I have to say but I would not be so bold to say it was a better way of playing. Also that did make an early conquest of a homeworld, even a primitive one very unbalanced. still, it did not feel so bad that i would totally exclude reducing pop numbers and growth from the solution. As others said. It is abstract anyway.
Maybe you also could add something like "super" pops... 1 super pop is 10 pops... a super pop can be part of 2 factions or 3. Just brainstorming here...because even if we feel somewhat connected to our first 50 pops (and I doubt that), who even knows and cares by the endgame what his empire is made of?


If it matters I made a similar home brew mod:
  • Cut POPs, GROWTH speed, ASSEMBLY speed, JOBs, HOUSING, etc.
  • Rescaled job production to compensate for job cuts
  • Tried to rescale buffs, change build weights, etc.
I enjoyed similar changes myself and oddly found the economic AI SEEMED to do a little better themselves [build weight changes?]
 
Why though?
Is there an actual NEED to check every 7 days, opposed to every time there is a change in pops?
Would it not be more effective to run the check only if a pop (or a job) got added/removed from a planet? after all, if you have the same pop and same jobs, the job distribution should stay the same, no?
And I don't think anyone reaches a point where the pop count and/or job list of a given planet changes more than once every 7 days (except when using resettlement probably. that could cause issues, but if resettlement is ordered to run a "delayed check" of sorts, only checking after a few days without a resettle, that could solve that issue)


As odd as it sounds I [almost] wish we had a mode where the game didn't check at all. Maybe once a month it could say "hey any jobs available" ... "hey any unemployed" ... first unemployed gets the job. Then you could let the player manually reshuffle pops to jobs and lock those in place.

I would WELCOME smart automation [job priorities, job templates, etc.] to better handle things and so that you could prune the POPs when searching for a POP to fill a JOB.
 
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.
Idk. It is held by some that the pop of our planet will most likely level off around 9 or 10 billion for the foreseeable future. It makes sense that populations would hit a plateau for growth and reproduction would become a way to maintain the level instead of increase.
 
I wanted to sleep on it before commenting and read the thread. Many - including me - are happy to see this, but I see another trend. Many are cautious. I'd like to focus on that.

While I greatly respect Moah's efforts in communication and the whole team's hard work, I have to see the big picture. Performance was summarily ignored for months and months. There was little or no feedback, and the whole emhpasis was pushed to paid DLC's, which received 99% of the discussion room. To be frank, the customers were ignored. Not one, not two, but a huge amount of customers felt that their #1 need was not important enough even for a proper comment.

What we're getting now may not be too little. No, it looks like a very good fix and as an IT architect by profession, I can appreciate the challenges. It is, however, far too late. The tech may be fixed, but the attitude is not. Please note that I am not pushing this comment to the devs, this is a question about policy. This problem has not been answered and I would personally like to see an answer to it. Why was this matter ignored so long? Why were paying customers being made fun of?

I've been playing 2.1.3 for a while now, as it is at least playable. I will try the new version. If I find it playable, I will considering putting money down for DLC's as well. It will, however, also depend on the attitude. I would like honesty, admitting that there are problems. It may take a while to fix, even a long while, but the wait should not be done in silence.

I do apologize if I sound too picky about this, but I'm seeing far too many warning signs here and I'd hate to see a good, independent, skilled game studio drop down into the EA zone.
 
@KyuuET : My feeling is that Paradox was a little too focused on short-term-ROI and may not have properly valued fixing the flaws that the customers saw / experienced. Basically as long as that sweet DLC $ was still flowing in why should they spend the resources fixing the game for the "few" that saw problems.

IMHO the long-standing-known issues [Performance, AI, broken Crisis, broken (?) Awakened Empires, "balance", ...] has been the number one problem with Stellaris from my personal POV. Compound that with some controversial game design decisions from about 2 years ago and you have a recipe for the perception that Paradox doesn't care [enough] about the things that initially drew fans to the game.
 
@KyuuET : My feeling is that Paradox was a little too focused on short-term-ROI and may not have properly valued fixing the flaws that the customers saw / experienced. Basically as long as that sweet DLC $ was still flowing in why should they spend the resources fixing the game for the "few" that saw problems.

IMHO the long-standing-known issues [Performance, AI, broken Crisis, broken (?) Awakened Empires, "balance", ...] has been the number one problem with Stellaris from my personal POV. Compound that with some controversial game design decisions from about 2 years ago and you have a recipe for the perception that Paradox doesn't care [enough] about the things that initially drew fans to the game.

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.

Nevertheless, regarding the increasing population problem: my five cents of ideas would be in an direction, which i doubt that many like:
Big farms have the problem, that because of monocultures the risk of diseases is growing up to an point, where nothing helps anymore and the disease gets its way, making place for other plants to grow there again. The same counts for animals and for us humans (which is only another family of animals in some sense): as more and more people are on the planet, the fear of some super- killer-virus and whatever is more and more appering. Putting this into the game would mean, that at some point, where you have reached an certain level of overpopulation could then lead to some super-disease killing big parts of the population in your empire. In its wake, a lot of new independend realms shows up. You are thrown back into an much smaller part of your former empire and now have to deal with all this new empires again.
Additional to it they could put some declining rescources into the game. I never understood, if i mine asteroids, that this asteroids lasts forever. at some point there are no minerals there anymore! The same counts for everything else. And having an very old empire, which were mining recources like crazy, should have gotten to an point, where it is more and more difficult, to fullfill the need for recources any more.

This were my five cents of thoughts to this topic.
 
@Moah how many modifer checks are you doing at each calc check? would it improve daily and monthy checks by looking at a permanent new number instead of making base*twenty or so mods why not do the calc once and set a new target number for any lookups and only modify it as research or events happen so its just an integer and not a cycle of cpu time