Appendix C. Compile-Time PerformanceInterpretation of template metaprograms is inherently inefficient. When a class template is instantiated, a C++ compiler must meet all the standard's requirements, including matching against partial specializations, building an internal representation of the class, and recording the specialization in the template's namespace. It may also have to meet requirements imposed by its own design or that of the environment, such as generating mangled symbol names for the linker or recording information for the debugger. None of these activities are directly related to the metaprogram's intended computation. This inefficiency manifests itself in the time it takes for a program to compile and in the resources used by the compiler. Extensive use of metaprogramming without understanding its costs will magnify these effects. Because your metaprograms will typically be used by other programmers who care more about a quick compile/edit/debug cycle than how your library is implemented, they're not likely to be understanding if compilation gets very slow or stops because resource limits have been exceeded. Fortunately, problems are not inevitable, and can be avoided if you know how to keep the situation under control. Appendix C gives you the tools to analyze and manage metaprogram efficiency. |