settintotrieste / Victoria-2-Cold-War-Enhancement-Mod-CWE

CWE brings Victoria 2 into the Cold War era and beyond. This is the ultimate Cold War mod with a slew of special features such as ideological blocs, dynamic international institutions and decolonisation chains to accurately simulate the Cold War and Post-Cold War world.
https://discord.gg/BPJcMuN
123 stars 82 forks source link

Optimizations - POPS #116

Closed EmperorRAG closed 7 years ago

EmperorRAG commented 7 years ago

This thread is for the continuation of the discussion relating to pop optimization that was started in #109:

Initial post

I was taking a look at how Victoria 2 does calculations involving pops and I saw that the mods performance could be improved. If you were to make craftsmen and capitalists stay only in the state capital, you would reduce pop fracturing. The reduction of pop fractures would decrease the amount of calculations required for pops in the game session which would increase the game's performance. The proposed change would also tie into the urbanization patterns that follow industrialization therefore making the mod more realistic. Additionally you can go further and make it so that all pop types besides farmers, teachers, laborers, entrepreneurs and aristocrats only present in the state capital. The results of the additional change should greatly increase performance as well as aid the game in performing pop promotion and demotion. The most noticeable impact from the changes will most likely be reduced RAM usage, although it would be dependent on the user's PC.

Pop logic

the pop promotion to craftsmen isn't limited to state capitals, pops in all provinces will continue to promote to craftsmen but on promotion will teleport to the capital.

All that needs to be done is the changing of pop types; so an example could be 5000 craftsmen in a non-state capital province being changed to farmers/laborers and then in the state capital province changing 5000 farmers/laborers to craftsmen.

Solution to the crash

The crash comes from the pop type needing to be in a state capital province but due to it not being in the state capital province the game crashes, this issue is caused from the pop types not being teleported to the state capital province as they weren't promoted or demoted.

ARR8 commented 7 years ago

From the other discussion: state_capital_only is a built-in property of pops, which in vanilla is applied to aristocrats, capitalists, and bureaucrats, and in the mod currently only for soldiers and officers.

The migration factors already include some urbanization logic:

modifier = { factor = -1 location = { is_state_capital = yes } } modifier = { factor = -1.0 OR = { type = farmers type = labourers } }

If, for any reason, we can't move all the pops into state capitals, we can instead strengthen this heavily for the desired pop types, so that they will probably migrate to some state capital on their own. If needed, we can also add a push for farmers and labourers in state capitals or those with urban terrain for a "ruralization" though I imagine this isn't as necessary. This would still lower calculations by merging pops, but it is unnecessary and not preferable if the former is possible.

EmperorRAG commented 7 years ago

The game doesn't crash anymore if you change the pops to state capital only without changing the pop demographics. Good news is that it will still deliver better performance during game sessions, but I want to know if you would still like the pop demographics to be changed. Changing the pop demographics will only improve on loading times though.

ARR8 commented 7 years ago

IMO it's not worth the work, unless there's an automated way to change it. Is it a noticeable performance change?

EmperorRAG commented 7 years ago

In the early start date, there isn't initially a change in performance. As the game goes on though, you do notice the difference. The change has the most impact on the modern day start because there are many different pop cultures in the western nations which require many more calculations. Overall the betterment in the performance is more aimed over a long game session than a short one unless you start in the modern day scenario.

ARR8 commented 7 years ago

It sounds like you've gotten it working. I would submit a PR, then. I personally like the idea; care to weigh in, @settintotrieste?

settintotrieste commented 7 years ago

Sure @ARR8 , I have been thinking about whether the change will affect split states, does the allocation of state_capital_only prevent pop promotion to those pops in say Gibraltar which is a split state? Other than issue, I am ready to implement the optimisation.

settintotrieste commented 7 years ago

Changing to state_capital_only causes crashes when nations with split states are released with secede_province. As the mod requires secede province commands for many crucial features, this method of optimisation cannot be pursued.

EmperorRAG commented 7 years ago

I think this crash is due to the POPS not actually being in a combined POP group as the soldier pops and officer pops are combined into one POP group. The crash just means that until all the POPS that are affected are combined into a single group for each state, it won't be viable.

settintotrieste commented 7 years ago

In this case it would be better to make only rich strata pops state_capital_only but I will have to do some testing on this feature first to make sure that there are no crashes.