Performance Issues? My road to high pop

My Town

So the town I am currently working on has about 27 hearthlings at the moment. A lot of people have had issues with the game becoming laggy/unplayable before it reaches that point but after playing the game in debug mode I think I’ve figured how to get your towns optimal and break that 20+ pop barrier. I"m at about 7K+ food, 25K net worth and I have more workers than I know what to do with. Given some of the things I’ve discovered about the game and how it works I don’t see any reason I wouldn’t hit 40+ tonight.

Pathfinding Problems

Pretty much pathfinding is broken-ish or slow. This is a difficult problem given the three dimensional space and distances covered. Check out the latest pathfinding blog post for a better idea of what the dev’s are doing to fix this. This is getting fixed I believe (alpha 12?) but in general there are some best practices to keep in mind. I took the following screenshot of my town to show you what’s going on:

My Town Screenshot!

As you can see, one of the pathfinding tasks is taking up a huge search space to try to get to some items in the northwest corner of the map. There are stairs going up to the second level but pathfinding is trying to get to the closest block on this level to the target instead of figuring out to go up a level first. This means that all those items on the second level is blowing up my performance.

The easiest fix is to simply give pathfinding what it wants. If I build a ladder right there where it’s looking for one then the issue goes away and pathfinding goes on it’s merry way. You can see on the northeast corner I have a mine for a coal vein on the third level. I’ve started putting multiple ladders so wherever pathfinding wants to go down (or up) a level the ladder is right there. This speeds up the search space dramatically.

Both lua and pathfinder are pretty manageable right now. I’m using a fairly moderate cpu (AMD) so there is a lot more room for performance there compared to say an i7. If you want to understand a little more on how pathfinding works I suggest you check out this page: PathFinding.js I believe Stonehearth is using A* from what I can tell in the source code so you can see from the visualization just how many cpu operations are required to get from point A to point B.

This is where your hearthlings sometimes sit there stuck. If the pathfinder takes too long it actually starts over, and over, and over. They can’t figure out how to get to the task fast enough so they try again and because that task is still high priority over let’s say… eating they stand there hungry. You compare that to when you send a party out to attack a camp far away and after the fight they just lay down and sleep on the ground, it’s because it can’t find a bed and sleeping is more important than patrolling. So it’s important to “unstuck” these weird path glitches and optimize your town.

Optimize Layout

The best way I found to keep your town growing is to optimize the distance they have to travel for their jobs. If you look at my farms, right next to it behind the dining hall are 8 crates dedicated for food and plant storage. This guarantees that taking stuff from the farm to storage is as quick of a path as possible.

Across the way from the dining hall is the kitchen. This guarantees that a cook looking for ingredients do not have to travel (or rather search) very far to get the raw materials. All the workshops have storage right next to them specific to their trade. The blacksmith has all ores and metals storage right next to it, same for the weaver. This keeps the economy humming nicely.

Focus on making sure that containers are used and set for the appropriate tradesman that works right next to it. Also the paths are cached so when someone walks from their workshop to a target storage container they do not have to recalculate the path.

The next step (which I’m in the process of doing) is to segment off big chunks of the town inside of walls since they will break up the search space for pathfinding. I am playing in debug mode so I can see when these issues creep up but in general you will have tasks that take you pretty far away (e.g. cleaning up loot from a goblin camp). Limiting the number of ways to get inside and out of your town will help keep the cache of solved blocks in and out of the town working for you.

Discrete Tasks

I have 3 cooks dedicated to turning wheat into flour. One cook dedicated to making flour into bread. One that makes stew all day. This is what they do, all day. I have one weaver set to make thread, another to make cloth. I use the maintain stockpile and let them keep at it. By keeping the production chain happy I can minimize the number of raw materials and items I have and how much storage I need. 9 wheat => 1 bread is a good trade off.

For example, corn has 10 stacks per basket and requires 3 stacks per serving. 1 basket of corn will feed 3 people. A stack of peasant bread has 40 and it requires 6 stacks per serving. Not only will this yield in the highest satisfaction but it is also twice the storage efficiency of corn. Plus wheat grows REALLY fast so it can provide a more stable production chain than getting a huge influx of corn at once you will eventually hit a point where you can have dedicated cooks converting it daily into flour and into bread.

Same for weavers, I put the maintain thread in inventory at a high count (200?) and when they’re out of silkweed they will go do worker things. The second weaver will convert to cloth and when they are out of thread they will also go do worker things. So you aren’t really punished by heaving so many specialized worker because so long as the input of resources are managed well they will just bleed over to do other stuff if they run out. I will most likely setup a third weaver to maintain the stock of leather.

When you have these raw resources coming in and they start working, so long as they don’t have to travel far to get and drop off items there should be very minimal impact to game performance so this part scales up nicely.

Limit Construction

Buildings for some reason blow up the pathfinder. If you look where I’m building a barracks on the second level there is a crazy flurry of activity there in the pathfinder. For this reason to prevent cascading performance issues I limit building to 1-2 things at once. I’m also always on the look out to make sure items on roofs have ladder access and stuck hearthlings can get down. Those are brutal on performance when it keeps trying to resolve a path that it can’t ever resolve.

You also don’t need crazy big farms. I have a huge excess of food with just a few plots dedicated to wheat, turnips, and carrots.

Pausing Helps

I’ve noticed a few times when things get really hairy, pausing helps. I’m not sure if this is true but I think some of the background calculations continue even when the game is paused, and since the game doesn’t “tick” it allows for some background stuff to complete. I’ve done this along with reset ui (F5 in debug) and got things to un-glitch and moving again.

Sell Stuff!

Every time a merchant shows up I pretty much clear out excess inventory. I am sitting on close to 7K worth of gold 14-15 days into my town. 100 excess wheat? Flour guys aren’t keeping up? Sell the excess and see if it happens again. Too much of a resource like silkweed or or crops? Make those fields smaller instead of wasting time.


I hope this helps people out, I am confident a lot of the issues we’re facing is being looked at already but any performance gains pathfinding makes will scale up with being conscious of how we build our towns. I’m hoping to start seeing 100+ villages!

1 Like

i have 38 ppl, 132k value, and i use fences to contain the pathfinding(a single hole makes the fences useless)
im realy looking forward for that new(less demanding) pathfinding in version 12

my original idea for my game was to dig up a whole mountain, i use blacksmiths and masons to process the stone and ore

but atm that picking up/dropping bug is slowing me down alot, almost unable to get my wood supply to my blacksmiths, so for now ill wait untill thats fixed :stuck_out_tongue:

oh and if you keep the debug option running it only slows you down(high network send)

1 Like