Extreme lag on large maps transportation network
Main-version: 20250506 Sub-version: 0d2a837
Maybe I'm playing the game wrong/too long, so don't know if this is expected or not on large maps. Creating issue with attached save game in case anyone wants to check it out and see if there is any obvious issues or improvements that can be made. To reproduce just connect a new road to the existing road-network.
I'm playing a very large map 512x512 autogenerated by https://settlers2.net/map-generator/ I play mostly just to explore and settle new lands and to connect everything with roads while listening on podcasts or youtube, while slowly pushing into computer territory.
Now when controlling about 75% of the map the problem is that when connecting a new roads to the road network the games freezes for 5-10 seconds. During this time the CPU % goes from 2-3% to 25-30% in the task manager. The computer is a i5 9500t with an d 48GB RAM. Placing new flag-post in between on existing road does not have any impact. Removing roads connected to the network does sometimes freeze the game but not always.
Such large maps are indeed not well supported as especially large road networks cause a long time for the routing of wares and peoples in that.
There have been improvements to that but further improvements likely require fundamental changes that are unlikely to happen in the foreseeable future.
So I'd suggest to keep that map size at 256x256 or below
After having a more detailed look at this, it appears to be related to the copious amount of mine construction sites set on this map in combination with the large path grid.
I could see the freeze in two occassions:
- Placing down a new road (like described above), letting
FindWarehouseForAllJobsgo through the 455 items. - Having a plank brought into a storage area, letting
FindMaterialForBuildingSitesgo through the 455 items.
Those mine sites were not connected to the grid, so all the path calculation was in vain.
Find attached the cleaned-up version of the map removing the sites. This reduces the freeze to a mere microstutter (if anything). Large-map-with-lag_cleanedup-mine-constructions.zip
Maybe I'm playing the game wrong
Well, some people might call you a madman for that indeed... 😉 However, I can understand this approach using mine sites as a placeholder to be build later. Maybe this can be supported somehow, such that the list these two functions iterate through eliminates sites that were never connected to any roads?
go through the 455 items.
455 mines or what are the items?
We had the idea of using road IDs to remove the worst-case for pathfinding by not searching for connections that don't exist: https://github.com/Return-To-The-Roots/s25client/issues/164
I guess it's time to revisit and implement that. One just has to be careful to keep those IDs in sync.
This can also be used in sea maps to speed up path finding using harbors.
455 mines or what are the items?
I was a bit unsure yesterday, thus edited my post. Now, I have checked with the cleaned up version and the list is reduced to 6, which I seemed to have missed in the cleanup. So I can confirm it is composed of the mines in this case.
We had the idea of using road IDs to remove the worst-case for pathfinding by not searching for connections that don't exist: #164
Thanks for the hint! I might have a look at it, but first need to understand the structures and pathfinding a bit better.