• 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:
It's the TOTAL amount of pops in the galaxy that currently causes intense lag. You having 1k or 1.5k pops doesnt matter at all, if the galaxy has 10k pops.

If you are serious about increasing game speed, get out the planet crackers :)

To give yourself some headroom you could MOD [or find a mod] that cuts down the number of POPs, JOBs, GROWTH, HOUSING, ... With the recent improvements the effort may not be worthwhile though if the "pain" is now somewhere else. We won't know until told or do some testing once we get the release.
 
...Why? Unless you're arguing that formless blobs are better for performance (which, granted, they would be), I have no idea how lacking simulation for the pops and their jobs would be better for Stellaris.

Indirectly this may be an appeal to go back to something akin to the tile system from 2.1 and earlier versions of the game. Not saying that's the way to go but it would reduce the number of variables that the game would need to juggle significantly. Then again lots of the playerbase would have a fit so that wouldn't likely be a winning move. (??)
 
Indirectly this may be an appeal to go back to something akin to the tile system from 2.1 and earlier versions of the game. Not saying that's the way to go but it would reduce the number of variables that the game would need to juggle significantly. Then again lots of the playerbase would have a fit so that wouldn't likely be a winning move. (??)

I'm thinking more having indirect control over your empire; managing your subordinates, controlling your core systems and having your choice of Governor--for example--matter because of how they're going to mismanage their sector. Trying to control what your population does by providing incentives for colonisation, trying to balance the short-term gain from outsourcing construction and management of things to the private sector against the inevitable downsides as Space Disney ends up with more money and political clout to throw around to get their way.

For planets, you could have each one with three bars--Population, Infrastructure and Pollution--that grow over time as each planet builds and spawns its way to its max potential. You set what you want a planet to be, and the local Governor handles the retrofitting; if Population overtakes Infrastructure, you've got unemployment, so then you deploy incentives for people to either migrate or stop making babies, or for businesses to set up shop there, or you provide the funds to speed up your own peoples' construction and development of the planet.

But you could get rid of planets entirely, and have each system be a single entity. Imagine if building habitats was handled like how we build Districts now, and the current planet view was the whole system.

That way, there's no need for jobs, and the resources are produced presumably by the system or planet itself; the current traits and other things like Mining Guilds would need a rework, but getting rid of jobs wouldn't be some death sentence for the gameplay.
 
Being purged is a job!
This is off topic but, neutering purge doesn't seem like it should be a a job. Other purges involve some kind of processing, i.e. deportation, murder etc., but what are neutered pops doing? They're sterilized, but then they just stand around being unproductive. Is it in a field? A warehouse? The streets? Seems like they'd leave on their own just out of boredom. Just doesn't seem like it's thought out.
 
Just something I wanted to point out - was watching the performance stream earlier, and I noticed that the performance tanked significantly while the planet screen was open. I'm sure the team must already know this... but in case they didn't, there you go.

Also, why is the creature in my forum avatar not in-game?
 
From what I've seen on the stream, there is much work to be done. It's fine as long as you don't touch a planet, but once you load one we're almost back to 2.5 lag.

Edit : Ah didn't see the above comment. Whatever, that makes 2 of us.
 
From what I've seen on the stream, there is much work to be done. It's fine as long as you don't touch a planet, but once you load one we're almost back to 2.5 lag.

Edit : Ah didn't see the above comment. Whatever, that makes 2 of us.

It sucks that you need to hide in a system to try to avoid as much lag as possible.
 
Is it possible to get these bug fixes into maybe like a 2.5.2 patch so we can have them before Verne and Federations come out? Or would that be too much of a hassle considering all the work that has been done?
 
Is it possible to get these bug fixes into maybe like a 2.5.2 patch so we can have them before Verne and Federations come out? Or would that be too much of a hassle considering all the work that has been done?

I suspect that would create a very large amount of work and we'd end up not getting the 2.5.2 patch very much before 2.6 anyway. Or it would break something significant. Or both.
 
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.

so without multiplayer we would have waaaaaaay better lategame? :confused: are 2 different versions of the game coming? :D
 
To be fair, I think a lot of pop lag could be fixed by taking most pop checks and turning them into planet-based percentages checked per colony rather than per pop. You'd still have pops who need jobs, and jobs who need pops, but there would be perhaps 100 checks for ethics, ect, (one per planet, based on local conditions) rather than 10000 (one for every pop), sort of like a local demographics thing, like the government tab has.

Of course, I'm not a programmer and could be completely 100% wrong.
 
1. Using the pop resetlement window is deathly slow and almost unusable if there is a large number of pops. Populating and updating the GUI takes ages, even while the game is paused.

Oh, quick note about this! Resettlement window is slow as hell but only if you have free jobs. If the planet you resettle to then runs out of free jobs, it won't lag every time you move a pop.
 
Great to hear that there are such performance improvements with the upcoming patch!
@Moah I'm curious how my current savegame is doing with the new patch. I think you might be interested in it too, for it's extremely late game with lots of pops. Here are some stats:

Stellaris version: 2.3.3 (I'm playing this one game for quite a while now)
Galaxy size: 1000 stars
Current date: 2985-03-05
Amount of empires currently in the galaxy: 193
Amount of colonies (planets, ring world segments and habitats): 941
Current amount of pops in my empire: 41508
Total amount of pops in the galaxy: 86260

It has quite some lag, so I hope the new patch will make it a bit more playable.
 

Attachments

  • ironman.sav
    17,5 MB · Views: 4
Last edited:
I still think they'll need to get rid of pops and jobs entirely at some point.

Or at the very least, just jobs.
And replace it with what?
 
I'm thinking more having indirect control over your empire; managing your subordinates, controlling your core systems and having your choice of Governor-
You know the best part? We don't need the whole system reworked in order for that to be implemented. Auto build just needs to work.