Victoria 3

Victoria 3

124 ratings
Profiling-based Optimization (Performance Mod)
6
6
2
2
2
2
2
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
1.155 MB
Apr 5 @ 9:35am
Apr 11 @ 5:45am
5 Change Notes ( view )

Subscribe to download
Profiling-based Optimization (Performance Mod)

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.
Popular Discussions View All (1)
1
May 9 @ 5:42am
Error in the Red Scare optimization part; and a (possibly?) speedier solution
Danarca
67 Comments
bakakyo May 17 @ 12:36pm 
the point 1 is ridiculous (not that the mod is bad, the way the devs made it work is bad). It's a clear case for an event based system when whatever has the potential to change a flag (like a change in government) fires an event that is picked and then changed accordingly
captain5555555555 May 16 @ 2:11pm 
If the issue with dynamic flags is that it triggers every tick, wouldn't a better optimization be a partitioned yearly check?
LiI_Perk May 13 @ 3:22am 
i really like the idea of this mod, but loosing dynamic flags isnt worth it to me. Maybe you can change how it works entirely? Flag changes come through diplomacy or law enactment, so these 2 things should trigger a check if the flag needs to be changed. Maybe assign a variable for each country that indicates if its eligible for flag check?! I will come back and check on your progress, love the mod still!
Mr. Güler May 11 @ 5:20pm 
update: it is working when you add in mid game
Mr. Güler May 11 @ 6:46am 
Hi. Can i add this for my ongoing game? Thanks in advance.
BallahBoye May 9 @ 7:16am 
Thanks @Brute! I also get colonial nations changing their flags when they drop autonomy levels. For example, my Persia puppet got the Union Jack in the top-left corner of their flag when I made them a Dominion as UK.

Is this normal with regard to your mod?
Brute  [author] May 9 @ 5:48am 
I really appreciate that many people have notified me of the error in my Red Scare Journal Optimization. Unfortunately I might need to postpone my modding work until the release of the new DLC, as I have been quite occupied with preparing for a German exam. I will correct that issue and implement new optimizations (hopefully) once I'm a bit free!
Brute  [author] May 9 @ 5:46am 
@BallahBoye Don't worry, most major nations get to preserve their dynamic flags. I only disabled dynamic flags for default nations, which comprises the majority of the tags. The performance cost associated with preserving the game flavor for major nations is worth it in my opinion.
BallahBoye May 9 @ 2:48am 
I loaded this mod in my (short) mod-list last. Game was faster but flags kept changing dynamically (ie. France's flag became white when Legitimist). Does this mean the mod doesn't work?
Brute  [author] May 7 @ 8:08am 
@EatSomeRice Interesting...I've never encountered such a situation. Can you confirm that you have not played with other mods that might have changed the AI behavior?