Search code examples
cfunctionoptimizationstatic

Can a static function be faster than a non-static one?


Can a static function in C be potentially faster because the compiler's optimizer sees all the call sites and therefore optimizes the epilog and prolog of the called function?


Solution

  • It in theory it can. Yet at the same time some modern compilers can perform so called "global optimizations", which are based on analyzing relationships between the code across translation units. This can include analyzing all the call sites for a given function in the entire program (as opposed to a single translation unit) and potentially extend such optimizations to non-static functions as well.