Stellaris Dev Diary #170 - Performance and other technical issues

  • 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.
Showing developer posts only. Show all posts in this thread.

Moah

Platypus Admirer
Paradox Staff
49 Badges
Sep 20, 2011
662
2.904
  • Crusader Kings II
  • Europa Universalis IV: Pre-order
  • Sengoku
  • Semper Fi
  • Europa Universalis IV: Res Publica
  • Magicka
  • Heir to the Throne
  • Hearts of Iron III
  • Europa Universalis IV: Call to arms event
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Art of War
  • Divine Wind
  • Cities in Motion
  • Europa Universalis III: Chronicles
  • Europa Universalis III
  • Crusader Kings II: Sword of Islam
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: The Republic
  • Europa Universalis III Complete
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: Charlemagne
  • Stellaris: Galaxy Edition
  • Stellaris - Path to Destruction bundle
  • Stellaris: Leviathans Story Pack
  • Stellaris: Galaxy Edition
  • Crusader Kings II: Way of Life
  • Stellaris: Synthetic Dawn
  • Tyranny - Bastards Wound
  • Shadowrun Returns
  • Shadowrun: Dragonfall
  • Shadowrun: Hong Kong
  • Prison Architect
  • Stellaris
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: Common Sense
  • Pillars of Eternity
  • Europa Universalis IV: El Dorado
  • 500k Club
  • Victoria 2
  • Europa Universalis III Complete
  • Europa Universalis III Complete
  • Europa Universalis IV
  • Stellaris: Galaxy Edition
  • Stellaris Sign-up
  • Tyranny - Tales from the Tiers
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:
If this is the case, then why do pops shuffle their jobs every 1 day in the current patch?
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.
The reason why this was being done is that jobs amounts are actually modifiers and modifiers can come from everywhere, so there's no real way to check only when something change.
HOWEVER in practice, there are only a few places where these things actually happen and they were easy to localize. Which we've done. We missed a few, but then we got a couple of bug reports saying "Jobs don't update when XXX happens" so we fixed that, and now, probably like 99% of cases where the number of jobs change update the job distribution.
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.
 
15% more than the current state is still a long way from acceptable.

Are there plans to continue focusing on performance to the same extent, or will we return to the status quo of "we are always working on performance"?
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.

can you say something about the improved multithread use? It would be very interesting to know, especially if there is a thread dedicated for checking the jobs or fleet movement. Actually i've looked many times in my performance monitor and one of my threads is at its peak and the other ones are idle the most time. Will you share a glimpse of your wisdom with us? :)
Unfortunately there's not much to say about it. It's not as thorough as most people would like, but there are a couple things we've manage to parallelize, and we've reworked our thread pool to be more reactive. We also improved how we distribute the tasks across the thread pool.
We're still looking into better usage, but we focused on the pops right now, as it was what would give us the biggest win.

Have you ever thought about just reducing the amount of indvidual pops (i.e. lower pop growth rate as well as housing and all the population dependent thresholds, while accordingly increasing the ressources create by jobs?).

An indivudual pop is an abstract unit anyway, so not why make the unit a bit bigger? I wouldnt care if my planets are maxed out late game with 40-60 or 100-120 pops if the ressources provided / supply needed is the same. I mean, before 2.0 the hard cap for pop units per planet was the number of tiles, i.e. 25.
Well there's two different answers to that. Yes, I've thought about it. A lot. It's even be discussed with @grekulf and the design team. But at the same time, as a programmer, it feels bad to have to change the design of the game because of technical limitations. We (The programmers of Stellaris) would much rather have a system where design decides what they want without having to think about technical issues.

Still I'm a bit confused and sceptical about the "jobs distribution is now only done on demand" as the solution to all slow downs. Will this really solve our core problem? I remember the Perfomance Megathread stating the problem of slow downs is not the pops checking for new jobs every day. According to the thread it is rather the pops checking once a new (vacant) job opened up - meaning once a new job is created all pops on the planet check everyday if they should leave their current job and take the new job. (EDIT: Here's GnoSIS post with the analysis: https://forum.paradoxplaza.com/forum/index.php?threads/performance-megathread.1253705/page-22 - Post 427)
Lots of (unemployed) pop were supposed to be even beneficial and their normal regular checks were much less of a problem in comparison.
It's not a "solution to all slowdowns" It's a solution to one of the most common slowdowns, and one that was compounded several times over through various mechanisms. It's not a magical bullet that will allow everyone to run a 10k stars game with 200 AI well into the 3000s.
The video does represent a best case scenario, and I think that games that don't have as many pops but have many fleet won't benefit as much.
We'll still be working to improve performance. My personal goal is to reach a point where people ask for a slower fastests speed, like they have on CK2.

Out of curiosity, are job checks/tests performed on "invalid pops"?
  • E.g. If i have 1000 pops in an undesirables cast [e.g. being purged] on a planet is the game running fewer checks on them vs someone in ruler/specialist/worker cast (on a daily - or weekly/monthly basis, now, i guess?)
Being purged is a job! So yes we also run checks on pops to see if they need to take the "being purged" or "being assimilated" job.

15% and 30% improvement in late game situations
More like 15-30% depending on your specific save and your machine, across the board.
 
Forgive me if I'm missing something painfully obvious, but every time I think about this I wonder why anything regarding jobs is checked more often than once per month.

As far as I know, all the consequences of jobs (resources, amenities, pop growth, defense armies and what not) are only checked at end of month, meaning that it is only at that very instant the jobs actually have any influence on the game. It does not matter if half your population is unemployed from the 3rd to the 17th day of the month if everything is brought in order immediately before job consequences are checked - those 15 days of unemployment do not in any way register in the end of month outcome.Similarly, I conclude that there is no point to correctly ordering jobs multiple times per month, as it is only the final ordering immediately before this monthly check that has any impact on the game.

Is it because you think monthly checks would possible confuse players and lead them to wonder why pops aren't moving?
That's exactly why. Immediate feedback is important to know what's going and plan ahead.
 
Thank you for the answer anyways :). Please go on with the good work! But as a general idea, why not dedicate a thread for every specific game task (as long enough threads available of course). That would maybe give much better (balanced) CPU usage and reduce lag. But i'm shure you already had that idea and there are reasons why it didn't happen until now.
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.

Are any of your synths purchased from a certain fruit-themed Megacorp? There have been consistent problems with desyncs and crashes on Macs in MP (Linux too, pretty sure). Purging some more of those unplanned features would be greatly appreciated by both myself and many other mp players.
We have fixed several non-windows OOS. We're still on the lookout for more.

You just reminded me that the Empire Opinion galactic map filter is a good way to hang a game. Even when paused it grinds my machine down from 60 fps to 2-3 sometimes lol.
I actually remember seeing a JIRA about that and it getting fixed. So it should be much better in 2.6

Here is that one hard to read graph with a few labels.
You people are incredible!

if u want to keep the design of the game but offer speed to those who want. why not make a slider that says half popgrowth but x2 pop production. so those with slower systems can play.
Well there's a half formed idea of adapting "Game Rules" from CK2, etc and have a full on sliderfest for people who love that, but it hasn't been worked on yet.

The problem is that no hardware can handle 1k stars galaxy with 20+ AIs in the endgame.
Both my work and home machine handle this ok. YMMV and all that.

Okay, I did forget to ask: what is platypi?
It's one of the plural of "platypus." One of the more controversial ones.

1) You mention desync issues in the dev diary, but you don't refer to it later. Does that mean you are still working on that? Or it is to be assumed that those got improved as well?

2) Would it be possible to make the job checking configurable ? Doesn't have to be in the GUI anywhere, it's enough to put it in a config file. I feel it will allow players to tweak the performance of the game to their liking while retaining the original feeling for those that might feel weird if their jobs don't update immediately. I would like this option for my multiplayer group, as one of my friends has a rather crappy PC. I think with this option enabled we could play more comfortably, while the 15-30% average performance increase in late game might be not enough for us.
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.
 
Performance improvements look promising but I also hope you decide to implement a feature to disable certain notifications because it's way too much. You were only streaming the game for about 10 minutes before it ended up looking like this.

View attachment 546887
I had an idea to group similar notifications together, haven't time to work on it, though.
 
One of our betas asked me to post this picture. I quote their comments after the picture:
image (3).png

"@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"
 
Couldn't pops that are identical be grouped together somehow and be handled as one larger entity in many cases? Though I guess that would introduce a lot of overhead.
They could be, and I've been toying with the fact, but if the comparison/grouping would be long fast enough to be worth it.
We've also talked about approaching this more as a statistics model and not have pops as a single entity. It's a lot of gameplay changes, though. So I'd rather we find a way to make this work and let design decide what they want, rather than force choices on them for better performance.

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?
There's plans, but they're not going to be in at release.