Improving Simulation Performance


The past week I dealt with that pesky issue I mentioned with cultural preferences dropping down in value over time for all polities. It turns out it was a very simple bug where I made an incorrect preference value calculation whenever I updated faction cultures (which in turn influence polity cultures and then cell group cultures). 

I also had the chance to implement the migration effect of aggression (or more specifically, encroachment) on unorganized bands. Basically, unorganized bands now feel pressured to move out of cells where there's a high presence of aggressive polities. This works out well since polities will eventually expand further as unorganized bands vacate cells just within their borders. I'm nowhere done with tribal aggression though. I have yet to implement the effects of aggression and encroachment on the unorganized bands that can't move out. Also I need to implement the effect that aggression will have between polities that share a cell or a border. But for now I will do another segue to solve a big issue that is giving me a hard time as I try to test the new features: Simulation slowdowns.

Something that is happening all the time is that whenever polities appear in a world, the simulation starts slowing down dramatically. From simulating 10,000 years per second to just a mere 100 years per second... This is not necessarily a bad thing. I would expect, as the simulation grows in complexity, for it to take longer over time to evaluate hundreds of different events and interactions between thousands of entities. The problem is that the game right now is nowhere as complex for that to happen as dramatically as it is. And with the simulation running that slowly, it's very hard to test the effects of the new features I have added so far. So I decided to spend half the weekend looking at the simulation data and improving the instrumentation. For that, I improved the debug mode (now called development mode, or dev mode, to avoid confusing it with actual code debugging) to add a second level of tracing. So now dev mode has three levels of tracing: None, Basic, and Advanced. These can be accessed by an updated Settings Dialog:


So, with the new advanced dev mode, I added a bunch of new instrumentation to track how many events of each specific type are being evaluated per second, and, more importantly, how many of them successfully trigger. This will not only be helpful to me, but also to mod creators who want to understand how their event mods behave within the simulation. For now, I'm just appending the new event data into the info box when advanced mode is enabled (work in progress):


This extra information has already been very useful to figure out what is currently slowing down the simulation. In the screenshot above you can see that only 24% of the evaluated events actually trigger, which is a very low number. Ideally, 100% of them should trigger to maximize simulation efficiency, although, realistically, a >70% trigger rate would be good enough. Here, the event that is causing problems is the Foster Tribe Relation Decision event. As you can see, events of this type encompass more or less one third of all events evaluated (3517 of 9992 instances) and absolutely none of them triggered. This is a huge problem because, beside the fact this event shouldn't be evaluated that frequently, it never triggering means that all that CPU time used to evaluate it is being wasted since it has absolutely no effect on the simulation.

So next week I'm going to focus on fixing that particular event, which is not going to be simple because it is a hardcoded event. This means that what I need to do first is to convert it to a modable scripted event (which is something I planned to do before the release of 0.3.4 anyway) and then tweak it to reduce its evaluation frequency and increase its trigger rate to something at least greater than 30%. This is not the only event that is causing problems, but it is the biggest one so far. So I hope to get a noticeable improvement in performance by converting  and tweaking it. Once I'm done improving the simulation speed to something that is manageable, then I'll be able to go back and continue working on tribal aggression.

Get Worlds - History Simulator

Comments

Log in with itch.io to leave a comment.

Even on my shit PC I can run it super fast, honestly love this game and am supportive to the end. Once it is fully complete will it stop being free?

(+1)

The game will remain free even after completion (if that ever happens hehe)

Oh hey, I would be willing to pay for a complete version if it exists one day tbh, like 5-10 bucks