why does the initial build for source take forever?
Because Unreal Engine is Massive. Your implied next question is the actual answer, "then why is it so much faster the next time?" You see, it goes back to C++ 101. Back in the old days you had to setup your built tool manually by producing a Make file or typing the massive amount of text out on the command line (which you then ran out of space because the command line only held so many characters before chocking which is why we went to make files). Performing a building in C++ manually is a multi-stage process. Modern IDEs take a lot of the fuss out of it today. The first step compiles .h and .cpp files into obj files by running through the entire code base one by one producing the obj files (object files). Inside the make file you actually had to tell the compiler, take this .h and these .cpp files to make this .obj file. Once the object files are been produced you can then call the linker which links up the object files and produces the final executable or dll or library object of your chosen OS.
Now the magic of obj files. With the OBJ files built the next time you run the compiler it will now check if any of the OBJs are out of date, only creating new OBJs for the files that have been changed. This GREATLY speeds up your build time, especially when you have only changed one file. Now if you hit Rebuild, it will take forever again.
Unreal Engine also adds a 3rd stage onto of Compiling and Linking, the Unreal Build Tool which runs over your code first, and produces secondary .h and .cpp files that include methods to how functionality is exposed to Blueprints and reflection information that allow us to use "Class" objects to instance objects.
Follow this question
Once you sign in you will be able to subscribe for any updates here