Friday, February 29, 2008

inline functions, the good, bad and ugly

I learnt while reading from C++ FAQ Lite at http://www.parashift.com/c++-faq-lite/ about the good, bad and ugly aspects of inline functions. So here they are

Inline function can make you code faster if used, but then if its used a lot of places as inline function, the code bloats up. This can also lead to more page faults and hence leading to serious performance issues. Sometimes function optimizations can actually lead to a smaller code being generated because code for function calls(basically stack usage) is optimised.

Did I say page faults can increase, but then if there were two function on different pages, then thrashing could have been more without inline functions. Also its more likely that code would be at the boundary of cache, so cache memory thrashing is induced there.  But then again if the code is at right in the middle of the cache then fetching code of another function in another page would take toll on memory via thrashing.

So is inline good or bad. Now that something very subjective I would say. Just like not every garment looks beautiful to the customer, inlineing is also based on the usage. A simple direct answer may very well be wrong.

No comments: