Profiling-based Optimization (Performance Mod)

If you liked this item, please rate it up on Steam Workshop page.

Author: Brute

Last revision: 11 Apr at 12:45 UTC (2)

File size: 1.15 MB

On Steam Workshop

Description:

(Note: what differentiates my performance/optimization mods from most other mods is that I believe optimization should have as little impact on the gameplay/game mechanics as possible. The only places I optimize are those where unnecessary calculations can be avoided with little or no influence on how the game should otherwise feel: I still love my mosaic of pops and tiny countries in Victoria 3!

Of course, you are always welcome to combine this mod with other optimization mods that have to do with reducing the number of pops. While I cannot guarantee the compatibility with major overhaul mods, minor mods should work with this one without any issue. I welcome fellow modders to contact me if you want to incorporate parts of the optimization I made here into any major mods, since they tend to have even greater performance concerns. )

People all rightfully point out that Victoria 3 tends to have significant performance issue towards the late-game, which is often (partially correctly) attributed to pop fragmentation. Most optimization and performance mods thus focus on reducing the number of pops. However, it seems like none has utilized the in-built script profiler to look at what exactly contributes to the game’s performance issue.

This mod is my personal project to optimize the game based on the profiling result. At this moment it contains two specific changes, where the original script used an highly inefficient method that lead to unnecessary calculation throughout the game, even though nothing is gained gameplay-wise.

1. Removed the constant checking of flag definitions for default countries:
Come on, while we all agree that dynamic country flags are brilliant, their performance cost is ridiculous. In essence, the game is looking at every country in every tick to see if they qualify for a different flag at that moment. This is the script item that contributed the most to early game lag and it continues to play a role throughout the game. Even though disabling this means that some countries might have funky flags (most notably colonial administrations), I would rather my game run smoother than having dynamic flags per se. I might change it to a more sophisticated method if there’s a way to only refresh the flag when needed (but it seems like the engine doesn’t permit that)

2. Changed the calculation for ‘Red Scare’ Journal Entry’s trigger to use a less costly one:
Previously, the is_shown_when_inactive uses this trigger:
any_country = {
has_diplomatic_relevance = root
has_technology_researched = labor_movement
}
This is kind of stupid. What this means is that whenever the journal entry system refreshes, it will iterate over all countries to see if anyone of them has diplomatic_relevance and also researched the tech labor movement…just so that this journal entry can be DISPLAYED as inactive.
I changed it so that when the labor movement tech is researched, a global variable will be set indicating that someone has researched it. Since this trigger only affects whether this journal entry will be displayed at all, not whether it will actually become active, there’s hardly any change to the gameplay.

———————

(4/8)Update: I have added two other optimizations to this mod, which were a bit more sophisticated yet will likely not produce as great of an effect as the initial two opimizations.

3. Change the AI calculation of desired army size bonus for small country.
Previously, AI desired army size will increase by 1 for every 100000 incorporated population, with the increase capped at max 10. I changed it so that if the country has more than a million incorporated population, the max directly applies without the need to calculate a division. Not going to be a big deal I suppose but still an improvement.

4. Rehauled the `Red Scare` Journal Entry’s trigger altogether.
I am still not satisfied with the monstrous performance cost of this journal entry even after my initial fix, and I decided to rewrite the logic altogether.
Previously, whenever the journal entry system refreshes, anyone with inactive entry will iterate over every other country and see if there’s one who has diplomatic relevance and council republic. This is very costly as journal entries are refreshed quite often.
The new code uses a yearly pulse event to keep log of every council republic in existence. In the `Red Scare` Journal Entry, the country will only iterate over the cached list of existing council republics and see if there’s anyone that has diplomatic relevance (plus being more than a minor power, which is suggested by the tooltip but was not actually implemented by the vanilla code?) This results in drastically reduced frequency for iterating over all countries when checking for council republics, and should result in noticeable improvement once a few years have elapsed (at which point labor_movement will have been researched and the journal enabled). A quick test suggests that council republics should still correctly activate this journal entry, thus there will be no gameplay impact at all.

5. Change the trigger for ‘Natural Borders of France’ Journal Entry
Apparently Victoria 3 programmers forgot the fact that they offer this trigger called any_subject_or_below, which is much cheaper than iterating over every country and see if they are a subject of France. Fortunately only France got to enjoy this privilege so the performance impact is not as huge as say ‘Red Scare’, but still appreciable.

Download
Revisions:

Old revisions of this mod are available below. Click the link to download.