Quake Wars Unity Build
Arne Olav Hallingstad10th October 2009
Home
Introduction
Unity Build is a way of compiling a project where all the source files are combined into a single file before compilation. See this link for more information.
- Reduced link time since you only have a single translation unit.
- Chance for the compiler to do better optimizations.
- Quicker compiles because the compiler is not waiting for disk-IO for the different source files during compilation.
Some disadvantages:
- Any changes to the source code will result in a full rebuild
- Possiblity for some obscure bugs because of header include reordering (also turning off incremental linking is recommended)
- Once a build has been started it cannot be stopped since visual studio only checks if it should stop compiling after having finished the currently compiling source file.
- Having to maintain another project configuration and the unity build source files for each project.
I added a unity build configuration for debug and release for the Quake Wars 1.5 SDK. The SDK includes the game project files, idlib project files and iddecllib project files.
Unity build files were created for all three of them, a python script were used to extract the source files from the project files.
To exclude all source files from the build process except the unity files a simple find/replace regular expression were used in the 3 project files, although it would make more sense to use a define at the top of all source files so they could be excluded by defining/undefining it.
Regexp find: \(RelativePath="[^"]*"\)\n\([\t]*\)\(>\) Regexp replace: \1\n\2\3\n<FileConfiguration\n\2\tName="Unity Build Debug with edit and continue|Win32"\n\2\tExcludedFromBuild="true"\n\2\t>\n\2\t<Tool\n\2\t\tName="VCCustomBuildTool"\n\2\t/>\n\2</FileConfiguration>
The idlib project constains 80 source files, iddecllib project contains 33 source files and game project contains 230 source files.
Compile Times
Compiles were run twice for each configuration, only the second run compile times were noted
=== Debug with edit and continue === idLib: 11 seconds libGameDecl: 9 seconds game: 2:00 seconds Total time 2:20 seconds === Unity Build Debug with edit and continue === Times: idLib: 3 seconds libGameDecl: 3 seconds game: 32 seconds Total time 38 seconds 73,9% reduction in compile time from using a unity build === Release === idLib: 1:07 seconds libGameDecl: 25 seconds game: 6:00 seconds Total time 7:32 seconds === Unity Build Release === idLib: 1:03 seconds libGameDecl: 16 seconds game: 5:03 seconds Total time 6:22 seconds 15,5% reduction in compile time from using a unity build
Here's an example unity build output from a compile with some pragma messages to help see what's going on.