One of the things that was pointed out in DD #149 was that one of the big performance bottlenecks with the game is pathfinding, particular with Bypasses (Gateways, Wormholes, L-Gates).
And it really is a hard problem. Harder the real-life pathfinding even. Because the RL guys do not have to deal with Teleporters being strewn all over the map!
I thought a thread seperate from all other performance discussion would be helpfull.
Here a bit of already mentioend background information:
"There was other topics, which pointed out that L-Gates and overall wormholes and other gates are also a major player for performance loss, because of the path finding.
Were you also able into looking this one? Is the patch also addressing this?"
It is worth noting that the game knows 4 kinds of bypasses:
A the restore and buildable gateways
B wormholes
C the L-Gate
D Mod created Bypass Networks. It was overread by many, but the L-Gate introduction added mod support to the bypass System. You can create your own network with your own rules.
The A and D networks are the big issues.
Class B is not much of an issue. It is little more then a Hyperlane you can not scan through. While you need a tech, eventually everyone will get that tech. Indeed non-Default Empires often ignore the need for Wormhole tech. The default State will be that everyone has access to every Wormhole. That time when you do not is really the exception, rather then the rule.
Class C can be a bit harder, but IIRC only up to 10 L-Gate Systems can spawn and all pathing has to happen through the L-Cluster Terminus System.
So that would be the equivalent of <10 extra Hyperlanes being added to the map (one from each L-Gate Sytem to the Terminus). Not a big addition given the literally hundreds of stars in the bigger galaxies.
Class A will just add geometrically increasing amounts of connections to a select few System. While that makes it easier to reach anywhere with a few jumps, it also massively increases the number of possible paths to check from that System. Most Systems have 2-4 Hyperlance connections.
What it does is (pathfinding wise) is add a Hyperlane connection between this System and every other System with a Gateway.
If there are already 10 Gateways active, adding one to a system will add the equivalent of 10 new hyperlane connections to the Sytem. Bringing the total to 12-14. And a 10th Additional Hyperlane to all the other Systems with Active Gateways. At only 11 Gateways, we already talk about 55 effective additional Hyperlane conections.
At 20 Gateways, it is 380 effective additional Hyperlane conections. And the 21st gateway would add 20 paths to the newly minted gateway System.
And 20 Gateways would not be a lot in a 1000 Star Galaxy.
And with D you have no idea how it would affect pathfinding, because the rules are unclear.
And it is not even only one D. There can be many D-class networks.
Possible Solution:
Part of the reason I started this, is to talk about a possible solution I came up with.
First, we have the static network.
That would first include the Hyperlanes. But it will also include the B and C class networks eventually.
B Class are a pretty clear addition to the static list. As I said, eventually everyone will be able to pass them. So having the ability to use them is basically the default state. If you really can not afford the check, you could even just have 2 static networks - one for those with the tech and one for those without it.
C Class is true for the same reason. Once Activated, the network is "open source". And the extra paths are marginal (<10 to the Terminus System, 1 for <10 Systems).
D Class I will ignore for now.
The thing is that we do not (nessearily) need to know wich path through the gateway network is the fastest. We only need to know if the path through any 2 gateways is faster then using hyperlanes. So you would calculate two paths:
a) a path using only the static network
b) a path from the start and end points to the nearest useable A Class Gateway respectively. The distance between any 2 gateway Systems is 0 or 1 jump.
And then you just pick wichever path is shorter.
A advancement would be to calculate both in paralell. If you do that, you would not even need to calculate each of them to it's end. If one finishes, the other can stop the moment it would end up with a longer path.
If you know that the Static Network can get you there in 7 Jumps, once your gateway path reaches at least 8 jumps it is pointless to even look at it anymore.
Now the big issues is that this can not support D Class networks as they are now. They either have to be removed or at least be reduced only allow Networks similar to B and C Class. Stuff that can be integrated into the Static Network.
And it really is a hard problem. Harder the real-life pathfinding even. Because the RL guys do not have to deal with Teleporters being strewn all over the map!
I thought a thread seperate from all other performance discussion would be helpfull.
Here a bit of already mentioend background information:
"There was other topics, which pointed out that L-Gates and overall wormholes and other gates are also a major player for performance loss, because of the path finding.
Were you also able into looking this one? Is the patch also addressing this?"
We haven't worked on that (yet). Unfortunately this is a problem for which we don't have a good solution yet.
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.
Add to that that, invariable, the pathfinding itself becomes more complicated because you get many more ways to reach the same point.
Until we find a genius idea, i'm not sure we can do much to improve that. I've suggested removing gateways/wormholes/l-gates but for some reason nobody likes it when i suggest we remove features. Go figure!
Ooh i really love this pathfinder rant going on, but just to raise the level a bit:
- Each fleet has different stances that need to be considered if a system is a valid point or not.
- Each system may or may not give you access to pass by ftl inhibitors and your diplo standing with that empire.
- Each wormhole has an requirement that they have to been explored.
Side note: The underlying hyperlane distance cache is ofc just a upper triangle since distance is bidirectional so space wise it should be n(n - 1)/2, still to big to be in L1 cache for huge galaxies O;P
It is worth noting that the game knows 4 kinds of bypasses:
A the restore and buildable gateways
B wormholes
C the L-Gate
D Mod created Bypass Networks. It was overread by many, but the L-Gate introduction added mod support to the bypass System. You can create your own network with your own rules.
The A and D networks are the big issues.
Class B is not much of an issue. It is little more then a Hyperlane you can not scan through. While you need a tech, eventually everyone will get that tech. Indeed non-Default Empires often ignore the need for Wormhole tech. The default State will be that everyone has access to every Wormhole. That time when you do not is really the exception, rather then the rule.
Class C can be a bit harder, but IIRC only up to 10 L-Gate Systems can spawn and all pathing has to happen through the L-Cluster Terminus System.
So that would be the equivalent of <10 extra Hyperlanes being added to the map (one from each L-Gate Sytem to the Terminus). Not a big addition given the literally hundreds of stars in the bigger galaxies.
Class A will just add geometrically increasing amounts of connections to a select few System. While that makes it easier to reach anywhere with a few jumps, it also massively increases the number of possible paths to check from that System. Most Systems have 2-4 Hyperlance connections.
What it does is (pathfinding wise) is add a Hyperlane connection between this System and every other System with a Gateway.
If there are already 10 Gateways active, adding one to a system will add the equivalent of 10 new hyperlane connections to the Sytem. Bringing the total to 12-14. And a 10th Additional Hyperlane to all the other Systems with Active Gateways. At only 11 Gateways, we already talk about 55 effective additional Hyperlane conections.
At 20 Gateways, it is 380 effective additional Hyperlane conections. And the 21st gateway would add 20 paths to the newly minted gateway System.
And 20 Gateways would not be a lot in a 1000 Star Galaxy.
And with D you have no idea how it would affect pathfinding, because the rules are unclear.
And it is not even only one D. There can be many D-class networks.
Possible Solution:
Part of the reason I started this, is to talk about a possible solution I came up with.
First, we have the static network.
That would first include the Hyperlanes. But it will also include the B and C class networks eventually.
B Class are a pretty clear addition to the static list. As I said, eventually everyone will be able to pass them. So having the ability to use them is basically the default state. If you really can not afford the check, you could even just have 2 static networks - one for those with the tech and one for those without it.
C Class is true for the same reason. Once Activated, the network is "open source". And the extra paths are marginal (<10 to the Terminus System, 1 for <10 Systems).
D Class I will ignore for now.
The thing is that we do not (nessearily) need to know wich path through the gateway network is the fastest. We only need to know if the path through any 2 gateways is faster then using hyperlanes. So you would calculate two paths:
a) a path using only the static network
b) a path from the start and end points to the nearest useable A Class Gateway respectively. The distance between any 2 gateway Systems is 0 or 1 jump.
And then you just pick wichever path is shorter.
A advancement would be to calculate both in paralell. If you do that, you would not even need to calculate each of them to it's end. If one finishes, the other can stop the moment it would end up with a longer path.
If you know that the Static Network can get you there in 7 Jumps, once your gateway path reaches at least 8 jumps it is pointless to even look at it anymore.
Now the big issues is that this can not support D Class networks as they are now. They either have to be removed or at least be reduced only allow Networks similar to B and C Class. Stuff that can be integrated into the Static Network.