I’ve been working on a software library for some time and have seen it grow to include a large number of types. This has gradually increased the time needed to build the library – in fact, to build the whole package in our CI system recently hit an hour. At that point, I needed to take action to bring the build time back to a reasonable level.
- Increase the number of cores on the build machine
- Reduce the number of header includes per source file
- Configure pre-compiled headers on the largest projects
The graph above shows the improvements with each step. Doubling the number of cores on the build machine halved the build time because much of the time is spent compiling .cpp files which can be done in parallel.
Reducing the number of header inclusions also had a big effect. Initially, I’d taken the approach that all headers could be included stand-alone, and they would include their own dependencies. For this large project, though, that turned out to be expensive – so instead, I produced a single header that included all the others in the right order. Although that also has drawbacks (like, any change to any of those headers forces all the project files to be re-built), it’s reasonable for the workflow involved in this area of work.
Finally, turning on pre-compiled headers had a really noticeable improvement – particularly in building individual projects within the package (which many of our developers will be doing). From what I’ve read on MSDN, the previous step was a pre-requisite – it’s recommended to have .cpp files include the same framework header files in the same order.