I am part of a small project that is doing some research code in C++.

Our work involves a lot of mathematics and due to its nature we often need to temporarily use other people's code/libraries. To speed our own iteration times we designed a template based interface that allows to treat almost any vector type, e.g. Eigen::Vector3f, glm::vec4... As if they were the same, this is fantastic for prototyping and making demos (which is what our needs are), since you don;t need to explicitly write down conversion code between one math implementation to another.

We are however running into the problem of really long compile times. It takes about 2 minutes at the moment to compile a file with a few hundred lines of code, and we are starting to loose some of the advantages of the template strategy (fast iteration).

Are there tricks we could use to speed up compilation without outright re-implementing everything without templates? (which is likely to bloat the codebase significantly). We already tried template instanciation, but since our types are often dissimilar and not known beforehand it's not helping much.

  • What's the limiting factor in your compilation speed right now? CPU? Disk? Memory? Something else? Dec 29, 2021 at 20:41
  • We profiled compilation using gcc and the biggest bottleneck atm seems to be the callgraph expansion, which I think it's part of the optimization process. I suspect we might be CPU bound.
    – Makogan
    Dec 29, 2021 at 20:44


Browse other questions tagged or ask your own question.