Do C# static functions perform better than nonstatic functions, beyond reduced memory usage?

Mark Rogers picture Mark Rogers · Feb 16, 2010 · Viewed 13.1k times · Source

I assume that public or private static targets must have reduced memory usage, due to the fact that there is only one copy of the static target in memory.

It seems like because a method is static that might make the method a potential point for further optimization by the CLR compiler beyond what is possible with a non-static function. Just a flimsy theory though, so I've come to ask you all.

Do static public or private methods provide any increased performance benefit beyond reduced memory usage?

(Note: I'm not interested in responses that talk on the problems of premature optimization. Certainly that's sound advice I follow everyday, but that does not mean optimization is not necessary at times. (double negative!). Allow me to indulge my curiosity, at the least)

Answer

Adriaan Stander picture Adriaan Stander · Feb 16, 2010

From Static Classes and Static Class Members (C# Programming Guide)

A call to a static method generates a call instruction in Microsoft intermediate language (MSIL), whereas a call to an instance method generates a callvirt instruction, which also checks for a null object references. However, most of the time the performance difference between the two is not significant.