c++ - Will instantiating templates in precompiled headers reduce compile times? -
example: include in precompiled header file:
#include <vector>
as few instances of vector, such std::vector, std::vector etc used in project, reduce compile time if instantiate them in precomiled header this:
#include <vector> template class std::vector<float>; template class std::vector<int>;
going further, make sense add dummy functions precompiled headers uses few functions:
namespace pch_detail { inline auto func() { auto&& v = std::vector<float>{}; v.size(); v.begin(); v.front(); } }
i'm unsure of of how translation units , templates work, seems me if instantiate them in precompiled headers, should mean not need instantiated every .cpp file.
update
tested on real-world code base visual studio 2017 , instantiations of commonly used template classes.
- with common templated class instantiated: 71731 ms
- without instantiation: 68544 ms
hence, @ least in case, took took more time.
it can make difference yes.
instantiation in translation units can exploit data in precompiled header, , compiler can read more c++ standard library headers.
but have maintain list of instantiations, compile-time optimisation might more trouble it's worth - idea end having opposite effect if have instantiations no longer needed.
Comments
Post a Comment