c++ - Performance impact of variadic templates -
in latest refactoring round of code, replaced bunch of template classes fixed number of template arguments variadic counterparts. quite bit puzzled find out specific performance test case had seen drop in performance of 20-30%.
a few git bisect roundtrips later, offending commit identified. literally consists of single change from
template <typename t, typename u> class foo {};
to
template <typename t, typename ... args> class foo {};
i have confirmed experimentally applying single change produces slowdown mentioned above. yet more puzzlingly, switching compiler version (from gcc 4.7 gcc 4.8) moves slowdown occurrence similar commit (i.e., switch fixed variadic arguments, in different class bar
).
to give bit of context, specific performance test case sparse computer algebra problem memory-bound , hence susceptible efficient cache memory utilisation. test case has been problematic spot in code (e.g., around gcc 4.4/4.5 used have manually tweak compiler options managing detection of cache line sizes in order extract max performance).
does have idea of cause behaviour? unfortunately, fear extracting reduced test case difficult.
edit
for reference, commit restored performance behaviour. unfortunately consists of revert non-variadic code bunch of classes (instead of 1 class). try come more confined example.
https://gitorious.org/piranhapp0x/mainline/commit/b952c613b42fe480fe4ed2dfd3e683eb9e38e4cd
it's broad question , usual suspect (as far i'm concerned) recursive handling of variadic template parameters in generated code.
you need check if methods use variadic template parameter implemented in way recursion happens @ compile-time, not @ run-time. give idea, might want @ examples, e.g., this answer of mine. recursion happens @ compile-time , real code single-step forwarding , expanding.
despite wrote, expect had adapt code, otherwise args
never hold else single parameter , totally pointless have variadic template parameter - forgive me if i'm wrong ;) (from comment might trigger above in code pass parameter pack to)
Comments
Post a Comment