1

I have a project of a Scientific computing kind, the core algorithms are designed using template programming. On the top level it looks like a chain call of functions that based on configuration assemble main types for the facade class and create an instance of that class. There are several, lets say, 6 parameters, that produces around 36 variants of the class. As you already can understand that it takes enormous time like 20-30 mins (Core-i7 and load memory to 100%, 8 GB) to compile on a regular PC. That why I need to set all the parameters to one value (6 variants) during development then it is bearable.

The question is how I can fix it without any substantial intrusion? Do you think pre-compiling each header would help?

user14416
  • 2,922
  • 5
  • 40
  • 67
  • Maybe this will help: http://stackoverflow.com/q/13068993/509868 – anatolyg Apr 07 '15 at 20:44
  • 1
    If the problem is that you have many translation units in which the templates are being instantiated, then it's possible you could separate the template definitions and put them in a .cpp file with explicit template instantiations for every combination of template parameters. That way the templates are only fully instantiated for one translation unit and the others merely look at forward declarations. – qeadz Apr 07 '15 at 20:45
  • 2
    Are those templates used only once, or many times? I mean are they being compiled only once or many times? If you use them in many places, then maybe use explicit template instantiation – Michał Walenciak Apr 07 '15 at 20:45
  • Clarification: Pre compiling template headers is not likely to help much. Use explicit template instantiation like the above comments say. – Mooing Duck Apr 07 '15 at 20:46
  • @MooingDuck pre compiled, with pre compiled instantiations, should help, no? – Yakk - Adam Nevraumont Apr 07 '15 at 20:46
  • @Yakk: I _speculate_ that pre compiled instantiations will make a massive difference, and pre compiling will make a minescule difference. But you can totally do both. – Mooing Duck Apr 07 '15 at 20:47

1 Answers1

0

There are probably no quick-fix solutions here but there are likely to be some changes you can make to the code base that will help significantly.

  • Make sure that you're only doing the instantiations in one source file rather than many. I can't tell from your question if you're saying the entire projects takes 20 minutes to compile or one source file.

  • Make sure that all the parameters are actually independent. Can one be inferred from another either directly or via another template class that maps one parameter to the other?

  • Add a level of "template indirection" where one class doesn't have ALL the parameters. Instead it has one or two template types each of which dictates part of the behavior, and these types are instantiated only once in a source file.

Mark B
  • 95,107
  • 10
  • 109
  • 188