Sometimes C++ compiles quickly, but sometimes it compiles slowly

I am new to C++ with the Unreal Engine (5). Last night the compilation process (with live coding) was quite slow - about 2 minutes (as far as I understand, this is normal compilation time). Today (after turning off and on the computer) and throughout the day the compilation process was very fast, 5 seconds maximum, even after changing both the header file and .cpp with adding new functions.

So my question is why sometimes it compiles very fast and sometimes it compiles much slower? Is this a problem with my computer or it is UE5?

This is probably due to RAM. The more free RAM is available, the more cores unreal uses for compiling. I would recomment upgrading or closing other processes to free up system ressources.

It’s also a matter of first time build vs incremental build.

If you have compiled once then the next compiles will only calculate what has changed (unless you do a clean + build).

I have the opposite effect. The more I compile, the slower it gets. At night it’s incredibly slow, so it’s probably just my computer