• 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:
Good job, any updates on AI?

So far nothing per the Stream earlier today. They wanted to talk performance and only performance which seems like a good idea.

They definitely said that they would address AI later as that was a popular question that popped up in the Stream. I "think" they said that the next Stream [or DD?] would cover AI. Would have to rewatch to be sure.
 
Think this will be my last post on this thread as i don't want it to even more offtopic, but did you read what i wrote in post #144 ? https://forum.paradoxplaza.com/foru...technical-issues.1335134/page-8#post-26275950

I'm expecting a 50% improvement and i explained my thoughts around it.
Guess i will hope to get the same 200% improvement as shown in the videos because 50% simply wont cut it i fear.
I see what you mean. What, precisely makes the game unplayable at that speed? Is it frustration, or time spent?
 
One of our betas asked me to post this picture. I quote their comments after the picture:
View attachment 546890
"@moah grab this picture and say that it is from i5-3570K based PC"
"hmm, the ratio of improved to old build showed slowdown up to year 2300 by about 10 percent on average... after that it was gaining speed, being 50% faster by year 2500
I think that can be explained by having more pops in first 100 years and improvements not kicking in yet and then it is winning, becoming super fast by the end. more than impressive"
"I think it is in fact linear and, again, tied to pops count, but due to wars happening at different times it has this funny shape (edited)
so in the end it is like two times faster, taking into account increased number of pops"
Can you explain how this graph and the quotes fit together? The highest number we see there is 50%, but your colleague is talking about a 200% increase.
 
The 200% increase is from the comparison video with a 1000 star galaxy with 20k pops in the year 2580. The new patch got through 6 months on fastest while the current patch on the same hardware only got through 2 months side by side.
 
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!
I feel at this time, the only way you could ever make it close to "quick enough" would be to to cap galaxies at 400 or so.
As long as 1000 Stars are offered without mods, people have that wierd requirement for unattainable performanc at 1000 stars.

And it is not really a game design issue. More a human psychology issue.

But, we ARE always working on performance. Always looking for new things we could improve. Today's improvements don't come out of nowhere, they come out of the work we've put in in the past, etc. Being skeptical about it doesn't make it less true.
Now you only need a [strike]spambot[/strike] automatic PSA announcer that writes "we are always working on performance" every time someone mentions that word (or a related one) anywhere on the forum.
Apparently with any less reminders, the loud half of the forum goers forgets it. :rolleyes:

There might be a special case where your asteroids event adds a "Bruce Willis" job where it won't be reflected immediately but only right before the economy update, but otherwise it works well.
Damn those Media Conglomerates! :p

Both my work and home machine handle this ok. YMMV and all that.
It really comes down to people having wierd asumptions of how fast the game should be running. With requirements being somewhere beyond "mathematically possible".

So as I said during the stream and earlier in this post: we've worked on OOS. We've fixed several, we're unsure how many are left because it's hard to know for sure without a huge number of people playing at once.
OOS are like race conditions. Except across several computers.
 
Do you mean the average time per day ingame ?
I wrote in my first post 1 ingame year took 4min and 4seconds on that particule playthrough before i stopped playing, that means on average each day took ~ 0.67 seconds.
244 sec / 365 ingame-days = ~0.67 (real) seconds per ingame-day

Hoooold up! You're considering less than a second per in-game day to be unacceptable? Dude that's really ridiculous. I'll happily play through 2-3 secs per in-game day, and here you are saying less than a second per day is unacceptably slow?! (And I'm playing on a potato laptop too!)
 
This has probably already been said, but if you're going to try and use nonsense plurals for words with non-english etymology please use Platypodes rather than Platypi.

No. It clearly should be platypusses. (My cat insisted. My cat is always correct.)
 
Hoooold up! You're considering less than a second per in-game day to be unacceptable? Dude that's really ridiculous. I'll happily play through 2-3 secs per in-game day, and here you are saying less than a second per day is unacceptably slow?! (And I'm playing on a potato laptop too!)

In all fairness, a second per day means you get through 10 ingame years in an hour, which can feel like quite the slog compared to the breeze of the early game when you fly through the first fifty years in an hour or so (at least that's what it feels like, did not actually measure). Different people have different "pain" thresholds, this is one of them.
 
Hoooold up! You're considering less than a second per in-game day to be unacceptable? Dude that's really ridiculous. I'll happily play through 2-3 secs per in-game day, and here you are saying less than a second per day is unacceptably slow?! (And I'm playing on a potato laptop too!)

You think 18minutes for 1 year ingame is fine, well each to their own i guess.

10 years in 3 hours ?

And remember the pop grow exponential, faster and faster the more planets you have, hence those 3 seconds for a ingame day will grow longer and longer.

Real question, have you had a playthrough where you were above 2k pops ?
 
Last edited:
In all fairness, a second per day means you get through 10 ingame years in an hour, which can feel like quite the slog compared to the breeze of the early game when you fly through the first fifty years in an hour or so (at least that's what it feels like, did not actually measure). Different people have different "pain" thresholds, this is one of them.

I suppose that's fair... But it just feels so... absurdly fast to me. I guess my potato of a machine has warped my idea of what "fast" is. Still, I feel this is a really great improvement for little old potato players like me.
 
So far nothing per the Stream earlier today. They wanted to talk performance and only performance which seems like a good idea.

They definitely said that they would address AI later as that was a popular question that popped up in the Stream. I "think" they said that the next Stream [or DD?] would cover AI. Would have to rewatch to be sure.

I think it'll be AI because it rhymes with platypi. Well, that and performance and AI are the two main topics so it makes sense to cover that next.
 
As a point of reference, in a new game (sub 2250) 1 ingame year takes 56 seconds for me. (with quarterly saves, faster without)
56 seconds / 365 ingame days = ~0.15 seconds per ingame day.

3 / 0.15 is a slowdown factor of 20 -> 20x slower then the game is supposed to run on fastest preset

I usually stop at a slowdown of around ~4.5x
 
Last edited:
One of the problem is that the game is based on modifiers. Almost everything is a modifier, and modifiers depend from other modifiers, and you never know in what state they are, so we can't easily thread modifier calculations.
But you also have chains of dependencies, like pops depending on planets depending on countries, so you can't parallelize these side by side. Then fleet depend on system, countries and maybe planets? etc...
It's not impossible, but it would be us saying "all right, let's stop working on stellaris for six months while we rewrite the way we handle EVERYTHING."
At the end of the day, I don't think we need to do that to improve performance. Tactical usage of thread pools helps a lot, and I'm already thinking of several other places where we can get a great result with a much smaller rewrite.
i'm shure you know what is the best for the game! I really appreciate your work and you'll find the best possible way for us. Thank you! :)
 
I think up-to 50% performance increase in lategame as shown above is not enough for this game to be playable lategame for me =/

I have 930 hours playtime and running a pretty high-end pc with 16cores and 32 threads-> my R20 Cinebech scores a 545 singlethread and 9.8k mulithread.
Normally i reach 1k pops around year 2300, and its around this time i have to stop playing because of the lag. (unmodded)

Lets say i can now get 50% more "pop performance", that means i can have around 1.5k pops before the game become unplayable again for me.
That will take me around 30 more years ingame i would guesstimate ? So with this soon to be released patch i can maybe play a few hours more before i have to call it quits again (?)

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 :)
 
Doesn't this illustrate the flaw behind relying on pops to begin with? The advantages of pops seem to be massively, massively outweighed by the disadvantages. It's like playing a Worker Placement board game, but every few turns the board doubles in size. It doesn't actually enhance the gameplay experience and just makes it more frustrating and tedious. And it sounds like it is a coding nightmare. Using pops as discrete entities sounds like it's just an inherently flawed methodology and will never give you acceptable performance.
 
I still think they'll need to get rid of pops and jobs entirely at some point.

Or at the very least, just jobs.

...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.