You know, I realize that was a bit rude and I apologize. Since you responded nicely I'll try to answer your questions as concisely as possible.I would, but the overhead of switching threads was too high...![]()
1. Are any of these threads dependent on any other?
2. Do the threads switch CPUs at any point?
3. How much of the CPU activity is dedicated to switching processes vs actually running them?
4. How much memory does each of these threads actually use?
5. How many threads the OS can handle is rather besides the point, isn't it - the question is if you will see any performance improvement by rewriting the entire game to be able to run everything in parallel.
1. Certainly many of them would be, but its not terribly relevant. The point is that Stellaris planets aren't dependent on other planets, only a monthly update of the global state of the game (err... galactic state) which makes them ideal for multi-threading. Threading is hard when you need to sync up constantly, on the order of multiple times per frame. Every 10-15 seconds? Fairly trivial for the level of processing that Stellaris is doing (e.g. we aren't working with 100 GB datasets or something).
2. Just not terribly relevant AFAIK. Maybe in some extreme edge cases.
3. Very little to switching threads or processes. A significant part of CPU and OS design is about getting good at this. As I stated and you can see from my image, the "context switch delta" is how often the CPU is switching threads ("context" refers to the current working environment). It's already going on thousands of times per second as you read this.
4. Threads generally don't require much extra memory. They can directly address the memory of the main thread and don't need to duplicate anything but what they are modifying. Furthermore the vast, vast majority of any game is graphics and sound, the actual data is just a handful of bytes per pop. Stellaris saves in their entirety are a few megabytes in size.
5. Yes, certainly. It's clearly the case that pops are a major component of performance. If you offload those tasks to a CPU core that isn't doing anything then effectively those pops now cause next to no performance hit on the main CPU core and the Stellaris game.