Tuesday, July 3, 2007

Factor parameter independent code out of templates

Commonality and variablity analysis….interesting word for a simple thing that we do

In non template code repliation is explicit, you can see that there's duplication between two functions or two classes. In template code replication is imlicit there;s only one copy of the template source code ..but replication happens when the template is instantiated multiple times.

Non type parameters and type parameters both can cause bloat.

There are a lot of factors involved in determining performance improvement like size of binary, locaity improvement, cimpiler optimizations, program's working set size.

The best way to find the effect is to just try it out on representative data sets and the platforms concerned.

Things to remember:
Templates generate multiple classes and multiple functions, so any template code not dependent on a template parameter causes bloat.

Bloat due to non type template parameters can often be eliminated by replacing tempalte parameters with function parameters ro class data members.

Bloat due to type aparameters can be reduced by sharing implementations for instantiation types with identical binary representations.


No comments: