Profiling template metaprogram compilation time

前端 未结 4 564
面向向阳花
面向向阳花 2020-12-14 17:11

I\'m working on a C++ project with extensive compile-time computations. Long compilation time is slowing us down. How might I find out the slowest parts of our template me

4条回答
  •  [愿得一人]
    2020-12-14 17:51

    I know this is an old question, but there is a newer answer that I would like to give.

    There is a clang-based set of projects that target this particular problem. The first component is an instrumentation onto the clang compiler which produces a complete trace of all the template instantiations that occurred during compilation, with timing values and optionally memory usage counts as well. That tool is called Templight, as is accessible here (currently needs to compile against a patched clang source tree):

    https://github.com/mikael-s-persson/templight

    A second component is a conversion tool that allows you to convert the templight traces into other formats, such as easily parsable text-based format (yaml, xml, text, etc.) and into formats that can more easily be visualized, such as graphviz / graphML, and more importantly a callgrind output that can be loaded into KCacheGrind to visualize and inspect the meta-call-graph of template instantiations and their compile-time costs, such as this screenshot of a template instantiation profile of a piece of code that creates a boost::container::vector and sorts it with std::sort:

    enter image description here

    Check it out here:

    https://github.com/mikael-s-persson/templight-tools

    Finally, there is also another related project that creates an interactive shell and debugger to be able to interactively walk up and down the template instantiation graph:

    https://github.com/sabel83/metashell

提交回复
热议问题