• We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

EU4 - Development Diary - 9th of April 2019

Bonjour everyone! It is I, Le French Paradox and I will be your host for this Dev Diary.

Today we will talk about Tech Debt. As @DDRJake has been saying, tech debt has been an important focus for the EU4 team since the release of 1.28.3, the latest support patch we did for the Spain update. While our designers are thinking very hard about the yet-to-be-announced big expansion that is to come, we programmers have been busy tidying up the EU4 codebase.

tidying up.jpg

Microsoft should team up with Netflix, I would watch the hell out of this show

Jokes aside, we keep talking about Tech Debt but realize it might be a bit confusing, especially for our non-programming crowd.

While EU4 was announced at GamesCon 2012, the actual development started a year before, which makes the code 8 years old. And of course, the team at the time didn't reinvent everything, bits were pulled from EU3, some of which are still in use today. I'll let you speculate which is which in the comments.

As I'm sure you all know, technology is a rapidly evolving thing, and software engineering is no exception. In 10 years the development practices have evolved, both because the industry keeps learning and inventing new ways to solve problems, and because the ecosystem (the hardware and software that runs our games) also changes.

10 years ago, SSDs were not that widespread, 1080p was pretty new, DirectX 10 was all the rage in previews and most people were so hostile to Windows Vista that they kept running XP in 32 bits.
That is not to say that EU4 was using only stuff from the late 2000s or early 2010s until now. Over time our engineers have done their best to keep the game up to date, but some stuff inevitably slips through the cracks. It's the accumulation of all this aging stuff that we call tech debt(*).

Here's a few examples of those things that we have tackled so far.

64 bits
As the BattlePope already explained in a past DD, 32 bits was a reasonable choice when EU4 development started, but today 64 bits in the norm.
With that done EU4 will keep running with the next update of MacOS (which removes 32 bit compatibility altogether) and also be able to use more RAM. While there are no immediate plans to increase the memory usage of the game significantly, mods that add a lot of provinces and tags should be able to break the previous ceiling.

Rendering
It is no secret that our games do not use cutting edge graphics. True to its board game heritage, Europa Universalis is mostly about showing a world map with some cool dudes (and elephants) fighting on top of it. Yet if you take a look at the Imperator preview, you will see that our graphics experts have learnt a trick or two since EU4's release.

2xnk41.jpg


While Boromir is (was?) right, we still managed to replicate some of the improvements they have made. The main one is that the colorizing of the provinces on the map is now done mostly on the GPU, while in the past it used to consume precious CPU cycles to display whatever horrible experiment in bordergore your game was about.

capture.PNG

Let's play 7 differences, can you spot what changed from the current release in this beta screenshot?

Crash reporter
Our game never crashes, it just tactically exits. Yet when it happens, we want to know all about it. It helps our QA to reproduce the issue and our programmers to isolate the piece of code responsible and fix it.
Since EU4's release our engine team has made a new and improved crash reporter that brings us more data and help find problems faster. First of all, it now works on Linux and MacOS, meaning we will be able to investigate issues on those platforms much easier. Secondly, it allows us to add some metadata to the dump, such as the current year, the list of enabled mods or how many 6/6/6 heirs died to a hunting accident, helping us understand what triggered the issue.

Startup time
Improving the loading time of the game is something we always want to do. While we can't really apply the best fix to the issue (discontinue Windows support, the game just starts so much faster on Linux and MacOS, trust me), we managed to find some things we could do.
The most notable one was the upgrade of PhysFS, a 3rd party software that a lot of videogames use to load all resources (files on disk, mods, DLCs...). While still far from Unix performance, it should shave off a couple seconds from the startup time on Windows.

capture.PNG

Experienced Byzantium players recommend playing on Linux or Mac due to the very fast restart time

General performance
The speed of the game is, of course, always a concern. Every night, we run a couple games on benchmark machines and always make sure that the averages are below a certain value (80ms per in-game day is our current high threshold).
While you may think that performance would improve over time (due to new hardware for example), in practice the average usually go up during the development phase of a new expansion, and is then worked upon to bring it back to acceptable values.
Contrary to popular thought, adding new features in the game is not the only (or even main) source of performance regression. In fact, one big factor is simply the addition of tags and provinces.
Consider this: for every two countries in the game, a bunch of stuff needs to be computed each in-game day (relations, AI attitude...). For every two provinces in the game, the game has to know the way from A to B (what we call pathfinding). This is known as a quadratic problem. For those who don't favor math, it means that for X provinces, the problem complexity is X squared. Doubling the number of provinces does not double the number of computations needed, it quadruples it. Over the years, part of our job has been to allow EU4 to grow from around 2000 provinces to more than 4000 provinces.
Keep in mind though that in software engineering an optimization that makes something 0.1% faster is considered pretty good, 1% excellent and 10% probably means you introduced a serious bug (or fixed a very serious one). How do we manage to improve anything with those numbers? Simple: all those add up in the end.

That's all for today! Should you like to know more meaty details of the tech stuff, you can check-out my blog where I get into more practical details about development practices.

Next week we should return to a more classic Dev Diary by our designers, unless you can help me convince Jake to revamp the wine trade good to include grape kinds and soils and finally settle which of the Burgundian or Bordelaise tradition of winemaking is the best.

(*) It's a bit more complicated than that but should be enough for the sake of this diary
 
Last edited:
Purely out of curiosity (I'm no programmer) but I would have always thought that as the number of tags decreases going into the later game (in most scenarios) that the stutter found in the late game would be reduced since there's not as many calculations? I just find it a little galling when I get to the last 20 or so years of a game and it starts to grind to an almost halt and capped out a core on my i7 9700k.

I think that the increase in the number of armies compensates that effect. Each big nation in the late game has to make more decisions (and probably more complex ones) than the sum of the smaller nations in the early game.
 
OK I think I am lost. What do you meant by SP lobby? Exactly?
When you click 'Single Player' on the title screen, the game history gets loaded and you are taken into a pre-game area where you choose what country etc. you want to play.

"Lobby" may not be the best word for it, admittedly, but it's the single-word term that springs most readily to mind for it.
 
@The_sherbet game engine takes in account also dead tags that could spawn from their core provinces. Idk if it rules them out once they cant be released anymore, but i think not

Even if this is true, the amount of affect it would have on the game compared to other, more CPU intensive calculations such as the actual living AI fighting wars and such is rather minuscule. I wouldn't be surprised if this is one of those "common knowledge" things that turns out to be false or at most only half true.
 
This is something I'm studying right now in the university so I'll try to explain some issues that arise with multithreading (not sure were to begin explaining though :p).

Even without deadlock the CPU cost of acquiring locks / synchronization can be quite high. Cache invalidation of variables loaded in CPU caches, etc. Lots of high performant systems have moved away from procedural languages+synchronization to functional languages and/or signal approaches.

Other considerations that will hamper multi-threading:
- debuggability
- calculations dependent on previous results
- calculations are independent but order specific
 
While we can't really apply the best fix to the issue (discontinue Windows support, the game just starts so much faster on Linux and MacOS, trust me), we managed to find some things we could do.
I take you're playing on Windows? NTFS (the way Windows arrange your files on your disk) is notably bad at accessing a lot of small files (such as our history files).
This is the main reason why Linux and MacOS starts much faster.
An obvious solution would be to put all core data in one big zip file but it's trickier than it sounds.

I don't recall a problem like this. Did you make a bug report?
Today's crash dumps are already pretty telling on what went wrong.
The tool itself will help for those edge cases where your game crashes but we can't find a reproducible way to trigger it.

Thank you for this post! I've been trying to figure out why Windows disk performance is so bad for some time now. Notably, when starting up Windows on my laptop with HDD 5400 RPM, after boot disk usage is at 100% for at least 15 minutes and it's just so infuriating! I noticed this doesn't happen when I have an SSD installed, which is obviously because accessing smaller files is so much faster on an SSD.
So, is entirely NTFS to blame regarding Windows' poor disk performance? Do you reckon if Windows had adopted any new, improved filesystem, would the situation improve?
Cheers!