x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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!

EDIT: I'm using Visual Studio 2017 Community, UE4.17.2 and Windows 10.

Product Version: UE 4.17
Tags:
more ▼

asked Oct 21 '17 at 02:49 PM in C++ Programming

avatar image

Null Terminator
11 1 2 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

4 answers: sort voted first

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.

more ▼

answered Oct 21 '17 at 05:13 PM

avatar image

lordmatthoffman
45 2 6 16

avatar image Null Terminator Oct 21 '17 at 09:32 PM

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.

avatar image lordmatthoffman Oct 21 '17 at 09:38 PM

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? :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Oct 21 '17 at 03:05 PM

avatar image

krisgoku2
91 5 8 11

avatar image Null Terminator Oct 21 '17 at 03:14 PM

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.

avatar image staticvoidlol Oct 21 '17 at 04:56 PM

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.

avatar image Null Terminator Oct 21 '17 at 09:11 PM

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

avatar image staticvoidlol Oct 21 '17 at 09:16 PM

Yup that would unfortunately not be the problem then.

avatar image lordmatthoffman Oct 21 '17 at 05:39 PM

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!

avatar image Null Terminator Oct 21 '17 at 09:12 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Dec 15 '18 at 03:10 PM

avatar image

denton85
11 1 4 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Feb 25 '19 at 04:21 PM

avatar image

glory13
65 7 9 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question