The question concerns the contents of the .pch binary created by the Visual Studio compiler. What does it contain? Is it only the parsed tree of the header files, or object code as well?
Consider this example:
// myheader.h
#include <vector>
class A {
public:
void add(int i) { v.push_back(i); }
private:
std::vector<int> v;
};
Would including this header in the set to be precompiled result in a complete template instantiation of vector<int> being compiled and added to the .pch?
To give some more context; if only the parse tree is precompiled, this means that object code for instantiated templates will still be created once per compile unit with resulting increases in compile and link time. So "unity builds"/reducing compile units would still be a relevant factor in decreasing build time even with precompiled headers enabled.
Though I cannot say definite thing about the internal of PCH,
as for unity builds,
even if vector<int>
is fully instantiated in PCH,
I think unity builds still has some advantage.
As you may know, C++ has to keep one-definition-rule(ODR).
Linker has to unite template's definitions scattered in each object file into
one.
That is, roughly speaking, C++ has to do the following:
Unity builds make it possible to save the above load in some degree.
However, I cannot say the above saving will surpass non-unity compilation
system with PCH in your environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With