Tag Archives: optimization
C++ - Optimizing away vtable with metaprogramming
Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wp-content/plugins/latex/latex.php on line 47
Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wp-content/plugins/latex/latex.php on line 49
In every object oriented language class inheritance is a life saver when it comes to program architecture. A rather nasty side effect that comes with it is usually performance degradation. And in C++ that penalty can be quite noticeable. When working with virtual methods in derived classes compiler generates vtable (Virtual Method Table), where address for each overridden method is specified. Vtable is then used every time virtual method is called to lookup that address, jump to it and execute code at that location. That penalty can quickly increase execution time by \(\). There is a neat trick that allows us to resolve those addresses compile-time allowing compiler to optimize vtable away using metaprogramming.
Continue reading →