Faster compile times?

Looking for ways to improve C++ compile times.

Right now even with my smallish project, compiles are taking 30-60 seconds just touching one .cpp file.

I had done some research and found these in .build.cs…


PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PrivatePCHHeaderFile = "MaulProtoPrecompiled.h";
MinFilesUsingPrecompiledHeaderOverride = 1;
bUseUnity = false;


edit - fixed/fixing compile errors, will report if I get any speed up

3 Likes

Is this on a SSD drive?
I had similar issues (compiling time) before moving UE4 Install and Project on a SSD.

Yes, it’s on a SSD drive.

Success! My build time for one .cpp file has gone from 60 seconds to 8 seconds using some additional options in my .build.cs file…


PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PrivatePCHHeaderFile = "MaulProtoPrecompiled.h";
MinFilesUsingPrecompiledHeaderOverride = 1;
bUseUnity = false;

Precompiled header helps speed things up too, based on some quick testing it looks best to have all the main Unreal headers there, and headers used commonly but not touched very often.



// MaulProtoPrecompiled.h

#pragma once

#include "CoreMinimal.h"
#include "Engine.h"

Also, when I hit compile it actually shows me what .cpp files it’s compiling in Visual Studio which is nice to see progress.

edit - This is such a huge productivity booster. Development is now much more fun. Definitely recommend for smaller projects.

4 Likes

Thanks for sharing, it helped a lot! This is something I was struggling with for a while now. I even heard some people saying they quit because of it…

1 Like

This still works great. I also found this article, which may help someone, though I haven’t tried it in my project:

http://kantandev.com/articles/ue4-includes-precompiled-headers-and-iwyu-include-what-you-use

You can’t, if you look at the activity where unreal is, for most of the time it’s built system is based on shadow copy, most of the time it checks to see if it’s duplicates and the actual C++ compiler is much faster once you get past this stage. So most of the time when you hit compile it will stay on shadow errors cpp to check and extra check for duplicates, I believe this is the unreal build system and not part of the C++ compilation and it’s dependencies. Unreal has a build system that takes the data, checks it for duplicates and then after all has been done it will finally pass it to the msvc system to compile the data with it’s header.

There is no way to skip the shadow errors step, I made a view into the process once it starts, a way to supervise the process once you hit compile, where is the build system at any moment, and most of the time it is spent there, after that , when it actually compiles the code, it’s very fast.

So my opinion is that this shadow errors stuff is part of unreal built system and not the compiler system offered by microsoft that I think is pretty decent. If you erase the Unreal chache that can build like 50 gb on your drive, the shadow error process will take even longer.

I think simply the unreal build system is unoptimised, if you have 8 gb of ram it will take a long time if you have multiple things to compile.