3

We have a big class with multiple template parameters. To cut down on compile time, we are already using explicit instantiatiation. While this reduces the compile time of everyone who includes the header, compiling the cpp file is still super slow.

Is there any way to tell the compiler (here: gcc and clang) to instantiate multiple templates in parallel?

We would like to have the same effect as putting template class Foo<T1>; and template class Foo<T2>; from the linked question into two different cpp files.

Since there are multiple cases of Foo and multiple different instantiations, having to maintain a file for each is not optimal. Also, the explicit instantiation as seen above is generated by a macro.

mrks
  • 8,033
  • 1
  • 33
  • 62
  • 4
    Yes put your explicit instantiations into separate compilation units. – Slava Feb 16 '18 at 15:40
  • That^ and use parallel compilation – Useless Feb 16 '18 at 15:46
  • I added the last paragraph to the question. Since there are many `Foo`s and `T`s (which are generated by meta-programming magic), having to generate the files by hand is really ugly. – mrks Feb 16 '18 at 16:40
  • 1
    Is this file changing frequently? Otherwise, using ccache or some build system that caches build artifacts can speed up subsequent compilations. – Praetorian Feb 16 '18 at 19:39
  • Yepp, ccache is already doing its magic. Even then, we can't avoid changes to that file. Having to avoid that file is a bad idea in my experience, because it leads people to use ugly hacks where they don't have to touch that file. – mrks Feb 16 '18 at 22:34

0 Answers0