• 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 #149 - Technical improvements

Hi everyone, this is Moah. I’m the tech lead on Stellaris and today I’m here to talk about the free 2.3 "Wolfe" update that will be arriving together with Ancient Relics, and what it brings to the table in terms of tech.

Stellaris is going 64 bits.
People have been clamoring for this for a while now, and various factors have led us to finally do this for this patch. I should temper your expectations though: while many have claimed that this would be a miracle cure for all their issues with Stellaris, the reality is somewhat more tame.

What does it mean?
The one solid benefit is that Stellaris is no longer limited to 4gb of memory, and won’t crash anymore in situations where it was reaching that limit. For people who play on huge galaxies, with many empires, many mods or well into 3000s, this will be a boon.

In terms of performance, though, it doesn’t change much. Without drowning you in technical details, let’s just say that some things go faster because you handle more data at once, some things go slower because you have more data to handle. In the end, our measurements have shown no perceptible difference.

Finally, the last effect of switching to 64 bits is that the game will no longer playable on 32 bits computers or OSes. We don’t think this will affect many people, but there you have it.


What about Performance?
I know that’s everyone’s favourite question, so let’s do our best to talk about it. First, let me dispel some notions floating around in various forums: Stellaris does use multithreading, and we’re always on the lookout for new things to thread. In fact between 2.2.0 and 2.2.7, a huge effort was made to thread jobs and pops, and it’s one of the main drivers of performance improvement between these version.

Pops and jobs are indeed what’s consuming most of our CPU time nowadays. We’ve improved on that by reducing the amount of jobs each pop evaluate. We’ve also found other areas where we were doing too much work, and cut on:
  • Ships calculating their daily regeneration when they’re at full health
  • Off-screen icons being updated
  • Uninhabitable planets doing the same evaluations as populated planets
Why do these seemingly pointless things happen? Well, we generally focus on getting gameplay up and working quickly so that our content designers can iterate quickly, and sometimes things fall through the cracks. Some of these systems are also quite complex and the scale of the new code is not so easily apparent. Sometimes, not limiting the number of targets is good enough because you’re not doing much but then, months later, someone adds more calculations or the number of objects explodes for unrelated reasons, and suddenly you’ve got a performance issue.

Modifiers
One thing that sets Stellaris apart from other PDS title is how much we use (or abuse) modifiers. Everything is a modifier. Modifiers are modified by other modifiers themselves modified by other modifiers, and sometimes by themselves. It’s quite hard to follow, and leads to every value being able to change at any time without your noticing.

“Why don’t you just compute jobs when a new one appears?” has often been asked around these parts. Well, a short answer to that is it’s really hard to know when a new job appears. You can get jobs from any modifier to: country, planet, pops. Each of these can get modifiers from ethics, traditions, perks, events, buildings, jobs, country, planets, pop, technology, etc.

Until now we were trying to calculate modifiers manually, forced to follow the chain in its entirety: when you recompute a country modifier, you then calculate their planets modifiers, and then each planet would recalculate their pops modifiers. Some of our freezes were just that tangled ball of yarn trying to sort itself out.

NexRiPkna2utTqAzF9H0DEjOCwHVsI4EejYO-vMQMh6QwUB-_uP7dXmpjkwXzOOKoiwDqkSzd9tlLmN3DlFN2R06A62od6XxWm8xh99XRDfRFRP3vVj42GBIaDaXSK7jjyKdS39b

This is our modifier flow charts. It’s not quite up to date, but gives you an idea of the complexity of the system (Unpolished because it’s a dev tool, and not made for the article).

No More!
For 2.3 “Wolfe” we have switched to a system of modifier nodes, where each node register what node they follow, and is recalculated when used, following the chain itself. We have modifiers that are more up to date, and calculated only when needed. This also reduces the number of pointless recalculations.

This system has shown remarkable promise, and cut the number of “big freezes” happening around the game (notably after loading, for example). It has some issues, but as we continue working with it, it’ll get better and help both with performance and our programmers’ sanity.

So, what’s the verdict?
In our tests, 2.3 “Wolfe” is between 10% and 30% faster than 2.2.7 right now. Hopefully it’ll stay that way until release, but the nature of the beast is that some of these optimizations break things and fixing the issues negate them, so we can’t promise anything.

IuIGuQ4cXPvjCEMWG_AowiNIFXhzpsPIcphmCVJD79vQqVMqUeZCqCoVfDlWDNZ3YNkAScYAJh2ebft947YsqoOhG7A_4pNBWxjZ6L9se5lkEEImNYZ4uOpTMWj-amEiwSYdirpd


Measurements provided by @sabrenity , using detailed info from the beta build. It’s worth noting the “SHIPS_SERIAL” purple line has since been eliminated.

AI
Another forum favorite, we have done some improvements to the AI. First, with @Glavius ’s permission, we’ve used his job weights to improve general AI job distribution. We’ve also done the usual pass of polish and improvements, and of course taught the AI how to use all our new features.


What else is new?
We’re also getting a new crash reporter that will send your crash report as soon as they happen rather than next time you start the game. We’ve improved our non-steam network stack for connectivity issues, etc.


All right, enough of my yammering. This has turned into a GRRM length novel, and even though there are many more areas we could cover, we’ll just turn this for your perusal.
 
Last edited:
  • 1
Reactions:
I think I am missing something here. Why is the set value of distance worse than the dynamic value of travel time?
bcs everything should be calculated in travel time - it all that matters in the end - faster is better. Shorter route is sometimes not good.
A>B distance is 10 - your fleet travel it in 5 seconds, but another in 3.44 and another in 7,11 - so time is more important than distance.
then you have to add travel time in a system from one jump point to the other - it is distance but your fleet has sublight speed so time again
then the more jumps you do the more time it takes - wind up and wind down time
so time is everything.
 
honestly hitching/stutter has never been my issue, OOM crashes have been since 2.0. I'm really looking forward to this patch now in order to actually play this game again.
 
@Moah A couple of possibilities regarding gateways. I have no clue how much, if any, of these would help.
  1. For Pathfinding purposes, make all Gateways connect to an invisible hub system with no travel time. This way whenever the number of gateways change (either through a new one being built, or an empire closing/opening borders), you are only changing one connection.
  2. Have a separate Gateway cache. Since all gateways are connected, this would keep track of, say, the nearest Gateway to each system, and a list of all systems that are closer. When a new Gateway is built, you look through that list, and if the new Gateway system is closer for some of the systems, then you update just those systems on the list with new values. Then you can compare a "[Path to nearest Gateway from start] + [Path from nearest Gateway to Destination]" to a normal path, then use the shorter of the two.
 
bcs everything should be calculated in travel time - it all that matters in the end - faster is better. Shorter route is sometimes not good.
A>B distance is 10 - your fleet travel it in 5 seconds, but another in 3.44 and another in 7,11 - so time is more important than distance.
then you have to add travel time in a system from one jump point to the other - it is distance but your fleet has sublight speed so time again
then the more jumps you do the more time it takes - wind up and wind down time
so time is everything.

Well.........shorter distance to travel will always be shortest time to travel. Picking two routes of 5 units difference will always result in arriving at a destination sooner if the shorter route is taken. Is this not how travel works in games such as Stellaris?
 
Well.........shorter distance to travel will always be shortest time to travel. Picking two routes of 5 units difference will always result in arriving at a destination sooner if the shorter route is taken. Is this not how travel works in games such as Stellaris?

you can heve 5 jumps to a destination (short path) or 3 through long hyperlanes (longer path) - longer in distance than those 5 but traveling by hyperline counts (is fast) and jumps count (are slow) and sublight takes a lot of time
this is an edge case but possible.
I would say that less jumps is the better in current stellaris setting
but people do mods, some may want to slow down hyperlanes travel time decrease wind up/down increase sublight speed - this would result in weird behavior
so time is the best equator in my opinion
 
Well.........shorter distance to travel will always be shortest time to travel. Picking two routes of 5 units difference will always result in arriving at a destination sooner if the shorter route is taken. Is this not how travel works in games such as Stellaris?
You need to fugure at least three parameters: sublight travel time, FTL travel time and time to perform all hyperlane drive charges. And then find fastest path, not shortest.
 
you can heve 5 jumps to a destination or 3 through long hyperlanes - longer in distance than those 5 but traveling by hyperline counts (is fast) and jumps count (are slow) and sublight takes a lot of time
this is an edge case but possible.
I would say that less jumps is the better in current stellaris setting
but people do mods, some may want to slow down hyperlanes travel time decrease wind up/down increase sublight speed - this would result in weird behavior
so time is the best equator in my opinion

I see what you mean and it makes sense. Ty.
 
Well.........shorter distance to travel will always be shortest time to travel. Picking two routes of 5 units difference will always result in arriving at a destination sooner if the shorter route is taken. Is this not how travel works in games such as Stellaris?

Currently, the pathfinding discussed in this thread is generally assuming (or at least I am assuming) graph distance, counted in number of nodes. So basically how many hyperlanes do you travel over. However, since there is travel in-system between hyperlane entrances, there is additional distance not being accounted for by this approach.

The additional challenges of correctly getting the optimal path based on the movement (both intra- and inter-system) of the fleet in question is... probably asking a bit too much. Calculations would be much more intense.
 
Thanks Moah. Very good to hear that Paradox are aware of the playerbases concerns regarding performance and that things are being done where possible to alleviate the issues.

2.2 ticked me off immensely, thats probably an understatement. But the sectors/automation dev diary and now this show that development is going along the right lines to make things good/fun again.

Keep up the good work guys, I will patiently await the next patch :)
 
Loving this DD!

Will you fix the lighting in multi-star systems? So far only the main star has a light source, making planets orbiting around secondary stars look weird.

Granted, not an important issue. But since this is an art-heavy DLC, they might invest in that as well. :)
 
Currently, the pathfinding discussed in this thread is generally assuming (or at least I am assuming) graph distance, counted in number of nodes. So basically how many hyperlanes do you travel over. However, since there is travel in-system between hyperlane entrances, there is additional distance not being accounted for by this approach.

The additional challenges of correctly getting the optimal path based on the movement (both intra- and inter-system) of the fleet in question is... probably asking a bit too much. Calculations would be much more intense.

for sure it will slow down , but how much? we don't know.
but inner system nodes are only few, they are defined and kept in memory (game knows their position - so could also know distances from each other in a system) - this gives you a base value for travel time in-system.
I agree that it might be a bit to much to ask, but who knows.
I think it is a matter of data structures in memory and how fast they are accessed and how much it might slow down the full feature algorithm.
 
I've just explained why this happens, and we don't have a good solution right now.

In regards to the performance hit of generating new systems from precursor event chains, what if you pre-generate the system during galaxy creation and leave it in a hidden state until an event chain is completed? Events related to the chain could be programmed to only appear within a certain hyperlane distance from the home system. This would allow the distance cache to already be generated during the game start and eliminate the need to re-cache once a precursor event chain is completed.

If the system is hidden from the galaxy map, players won't be able to select it to travel to. You could then setup a flag on the system to block AI empires from traveling to it until the event chain is completed. This might also better "regionalize" the precursor event chains much in the same way that fallen empires are placed on the map.
 
It's probably too late to ask at this point, but is there any chance we'd be able to get an ETA on when the next POP is due to complete? I like trying to minimise the amount of time my main species POPs spend in the worker jobs and it'd be nice to be able to time when to build a building without breaking out a calculator.
 
for sure it will slow down , but how much? we don't know.
but inner system nodes are only few, they are defined and kept in memory (game knows their position - so could also know distances from each other in a system) - this gives you a base value for travel time in-system.
I agree that it might be a bit to much to ask, but who knows.
I think it is a matter of data structures in memory and how fast they are accessed and how much it might slow down the full feature algorithm.

I mean, unless you want to assume that the devs just don't understand pathfinding algorithms--which I very much doubt--there has to be a reason why the solutions Spartakus has come up with (within hours of the post) don't work.

I agree that it's mainly a matter of data structures. I could more easily believe the devs did not optimize their data structures for pathfinding over the concept that they just 'don't get it'.
 
With regards routing tables I have no idea how your code works or what your requirements for storing routing data is, so my lame contribution may not be helpful.

A few years ago when I was playing around with network diagrams and big data analytics in python we would store all nodes in the network either as a matrix, or in a dictionary or list of value pairs, which could be interrogated with built in functions for shortest path, longest path, mean path length, betweenness, eigenvector etc. With associated logic for categorizing nodes by type. So in applying it to analysis of disease outbtreaks or opinion analysis on social networks we could track memes through different node types, or isolate nodes based on various characteristics.

Forgive my rusty memory on the topic.

It just seems that these type of problems may already have been solved.
 
With regards routing tables I have no idea how your code works or what your requirements for storing routing data is, so my lame contribution may not be helpful.

A few years ago when I was playing around with network diagrams and big data analytics in python we would store all nodes in the network either as a matrix, or in a dictionary or list of value pairs, which could be interrogated with built in functions for shortest path, longest path, mean path length, betweenness, eigenvector etc. With associated logic for categorizing nodes by type. So in applying it to analysis of disease outbtreaks or opinion analysis on social networks we could track memes through different node types, or isolate nodes based on various characteristics.

Forgive my rusty memory on the topic.

It just seems that these type of problems may already have been solved.

Seems like you were doing social network analysis. Fun times. :) However, most SNA is done on static networks, and the issues already highlighted in this thread by the devs is dealing with arbitrary additions (gateways) to the network. Dynamic network analysis is much harder.

Using algorithms that perform better on small-world networks might help; the effect of wormholes and gateways is to change the starmap to increasing small-worldness.
 
I mean, unless you want to assume that the devs just don't understand pathfinding algorithms--which I very much doubt--there has to be a reason why the solutions Spartakus has come up with (within hours of the post) don't work.

I agree that it's mainly a matter of data structures. I could more easily believe the devs did not optimize their data structures for pathfinding over the concept that they just 'don't get it'.

agree :)
I assume that they know pathfinding - they count distances for all stars and they do it quite fast ? didn't even noticed that it makes slows downs.
maybe it is some technical debt, maybe when the first version of stellaris was developed they had only this idea, and it worked till 2.0, as technical lead said when they added wormholes it made mass recalculations oh hyperlane distances.
maybe there are reasons we do not know about..
and as I told before I am no coder, so I might be wrong.
 
agree :)
I assume that they know pathfinding - they count distances for all stars and they do it quite fast ? didn't even noticed that it makes slows downs.
maybe it is some technical debt, maybe when the first version of stellaris was developed they had only this idea, and it worked till 2.0, as technical lead said when they added wormholes it made mass recalculations oh hyperlane distances.
maybe there are reasons we do not know about..
and as I told before I am no coder, so I might be wrong.

I'm clearly not as good at algorithms as Spartakus, but I definitely believe that the root issue is one of technical debt. If they're still using a code base that has not been updated since removal of the other propulsion systems, their pathfinding is likely using structures that were not optimized for starlanes.
 
Our issue is that we have a cache that contains the distance from any system to any other system, and when you add/remove bypasses or systems we need to recalculate this cache. This is further compounded by the fact not everyone has the same access to every bypass.
We have the "basic" cache which is only for hyperlan distances, and then we have a cache patch that adds distance through gateways accessible to that country. This country specific cache needs to be emptied whenever a bypass gets added, and towards the end game, every country starts building gateways, leading to mass cache invalidations and reconstructions.
I wonder if it would help matters to treat Gateways behind the scenes as if they were a hub-and-spoke connection, like L-Gates, rather than point-to-point connections. Essentially, as far as the pathfinder is concerned, there's a dummy system that takes no time to traverse, which all gateways have individual two-way connections with. Empires can have those connections blocked in the same way as normal hyperlanes, albeit with slightly different rules.

For instance, say there are 20 gateways in the galaxy, 19 in country A and 1 in country B. If the two countries declare war (so now they can't path through each other's gateways) the game has to look at 190 gateway/gateway connections and check each one for validity. Under a hub-and-spoke system, it only has to check 20 gateway/hub connections. If a new gateway was built, instead of 20 new gateway/gateway connections it only needs to create one gateway/hub link.

Again, this would be strictly behind the scenes; from the player's perspective it would still function as a point-to-point network. The "hub system" wouldn't really exist, your ships wouldn't spend any time there (so they couldn't be e.g. trapped), you couldn't colonize it - it would just be an abstraction to help manage the network.

Apologies if this is a trivial idea or has been mentioned already, it just came to mind and thought it would be interesting.