Slow C++ compile time for trivial changes (hot reload)

Hello everyone!
I’m experiencing very long compilation time for my C++ code.
I’m doing the C++ battery collector tutorial, therefore my code base is small (a few short classes).

Few examples:
Recompiling without doing any changes takes ~2 minutes.
I’ve added a few lines of code to one class (and only one class) and it took 5 minutes. In the video, the same changes took only a few seconds to compile.

Such slow compile times make it impossible to work.

Looking at the Resource Manager, I can tell that my hard disk is the bottleneck.
Another thing I noticed is that in the output log it prints:
" Added 2393 classes and 506 folders" when I only changed one class! Is it possible that it recompiles the entire engine every time I compile?

How can I fix this?

Thanks in advance!

I’m using Visual Studio 2017 Community, UE4.17.2 and Windows 10.

Well, this game programming isn’t a joke you can get by with a decent computer. But to be ultimate I say you need a computer the price of a house. A solution is to just “write a ton of code” or more then a line at a time when you compile.

That sounds reasonable but I didn’t have this kind of problem using Unity. Besides. I’m having a hard time believing that my hard disk is 60 times slower than the one of the computer in the video (as it took me 5 minutes and the video 5 seconds). Had it been 5 times slower, maybe, but 60?

Note that the line " Added 2393 classes and 506 folders" appears in my output log even I didn’t change anything in my code - is that supposed to happen? Because it seems as if something is not configured correctly.

Are you using the engine binaries or rebuilding from source? If you are not going to make changes to the engine it’s orders of magnitude faster to just use the binaries.

Unfortunately the best step really is better computer hardware. Putting all of Unreal on an SSD will certainly help, the launcher, your project, maybe even Visual Studios, etc. This makes the disk access much faster, but it won’t solve it for sure.

One thing that has been recommended in the past is to open your <ProjectName>.Build.cs and add these lines to the top of the constructor there:

PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
MinFilesUsingPrecompiledHeaderOverride = 1;
bFasterWithoutUnity = true;

The default settings in Unreal tend to be tweaked for massive AAA projects and these have been reported in the past as ways to help with that.

As far as the Output Log saying: Added 2393 classes and 506 folders this is because Hot Reload is actually compiling your entire game from again from all the source code (and trying to do various existing C++ compile time savers) but once the new code is built the game has to load the new code so that it actually gets run. So it’s loaded all 2393 classes from the dll and applied some internal patches to redirect old classes to the new ones.

In general, I’ve found that using Hot Reload in combination with creating blueprints based off of the hot reloaded code tends to be a bad idea. If you’re just changing the implementation inside a cpp file then things go pretty well. However, if you modify things in the header (change function signatures, add new variables, etc.) and then create a blueprint derived from the class you can run into weird issues when you go to reload the blueprint the next time after doing a non-hot reload compile. This is because when you hot reload and change data structures it appears to make “HOTRELOAD_” versions of stuff that you’ll occasionally see pop-up in Blueprints when trying to use data related to the hot reloaded code. It’s at this point that I shut down the editor and do a full compile as using the HOTRELOAD_* versions of things in the Blueprints tends to cause issues.

It is likely that they cut out the compile times in the video for the sake of making a better tutorial. Also when Unity projects get into the multi-thousand lines of code projects they also start to suffer from 1-2 minute compile times so it’s not just a problem unique to Unreal!

Regardless of what you change in a CPP file, the entire CPP file has to be recompiled. The same goes for header files, anytime you change a header, any file that includes that header (both other headers and cpp files) have to be recompiled as well. This is where the concepts of “forward declaring” comes into play, to reduce the number of headers a header has to include to avoid this.

You can easily see how with headers including other headers changing one little thing in a header can cause a cascading effect that causes huge amounts to be recompiled. This is probably not your issue but something to be aware of.

While I can’t speak for developers, I would imagine most AAA development machines are probably quad cores (with hyperthreading) or 6-8 core machines and fast disk access for the same reasons. If you think two and a half minutes is long, can you imagine how long it used to take to build, burn a build to disk and insert that into a console to test it there? :slight_smile:

I used the Epic Games Launcher to install the engine so I assume it used the binaries (is it right?)

That makes sense, but this project has few dozens lines, not thousands. Strange that it is slow with such a tiny code base

Yup that would unfortunately not be the problem then.

Thanks for the detailed reply.

I tried changing the build file, then changed a variable value to see if that helps. I then changed a single variable and recompiled and it took 2.5 minutes. Half the time the previous build took but the previous build had some actual changes (I renamed a method, for example).

I also changed the project’s directory settings so it would not index file content - I’ve seen a thread suggest that - but that had no effect. Am I supposed to change the project’s folder or the engine’s?

Are AAA devs supposed to experience long compilations as well? Suppose I add a new class and I want to test it, should it be such a long compilation process? I assume that the better hardware and bigger code base cancels each other out. It seems to slow development quite a bunch if it takes you so long to see your code in action.

I have same issue. for me it’s impossible to do c++ coding.
default c++ fps template. changeling single variable value leads to 5+ minutes in compilation. it’s like whole days wasted

need a solution for it asap.

Bump, same with me. really powerful computer but slow compile times. I have compiled a project on my PC without using unreal and then compiled the same project using unreal. Unreal typically takes 10 times longer. Half the time is spent pre-compile(unreal header and reflection stuff?), and then half is compile. Why is unreal so much slower? Would love more advise on how to speed up unreal compile times.