More on inlining...
Just came across this:
Method Inlining
There is a cost associated with method calls; arguments need to be pushed on the stack or stored in registers, the method prolog and epilog need to be executed and so on. The cost of these calls can be avoided for certain methods by simply moving the method body of the method being called into the body of the caller. This is called Method In-lining. The JIT uses a number of heuristics to decide whether a method should be in-lined. The following is a list of the more significant of those (note that this is not exhaustive):
- Methods that are greater than 32 bytes of IL will not be inlined.
- Virtual functions are not inlined.
- Methods that have complex flow control will not be in-lined. Complex flow control is any flow control other than
if/then/else;
in this case,switch
orwhile
. - Methods that contain exception-handling blocks are not inlined, though methods that throw exceptions are still candidates for inlining.
- If any of the method's formal arguments are structs, the method will not be inlined.
I would carefully consider explicitly coding for these heuristics because they might change in future versions of the JIT. Don't compromise the correctness of the method to attempt to guarantee that it will be inlined. It is interesting to note that the inline
and __inline
keywords in C++ do not guarantee that the compiler will inline a method (though __forceinline
does).
Property get and set methods are generally good candidates for inlining, since all they do is typically initialize private data members.
HINT Don't compromise the correctness of a method in an attempt to guarantee inlining.
From Writing High Performance Managed Applications
Comments
Anonymous
January 29, 2004
You may also check out Rico's recent post on inlining http://weblogs.asp.net/ricom/archive/2004/01/14/58703.aspxAnonymous
February 08, 2004
Why dont you inline small switch-case constructs?
Why was 32 bytes chosen as an IL size for inlining?
Are small loops not unrolled and inlined or is any loop just not inlined?
Why are struct parameters not inlined?
I get the impression that alot of code that could be inlined wont be.Anonymous
February 09, 2004
Moo, I'll see if I can get somebody on the runtime to address those concerns...Anonymous
February 09, 2004
The comment has been removedAnonymous
February 09, 2004
Sure its a compromise but there is more than one Runtime out there for different architectures. Server and Workstation, the difference mainly being the garbage collector running on a different CPU right?
How do these different versions differ on the JIT?Anonymous
June 01, 2004
runtime to address those concerns?it dosn't work!Anonymous
December 18, 2004
Helpful For MBA Fans.Anonymous
December 27, 2004
[http://itpeixun.51.net/][http://aissl.51.net/][http://kukuxz003.freewebpage.org/][http://kukuxz001.51.net/][http://kukuxz003.51.net/][http://kukuxz005.51.net/][http://kukuxz002.51.net/][http://kukuxz004.freewebpage.org/][http://kukuxz007.51.net/][http://kukuxz001.freewebpage.org/][http://kukuxz006.51.net/][http://kukuxz002.freewebpage.org/][http://kukuxz004.51.net/][http://kukuxz008.51.net/][http://kukuxz009.51.net/][http://kukuxz005.freewebpage.org/][http://kukuxz006.freewebpage.org/][http://kukuxz007.freewebpage.org/][http://kukuxz009.freewebpage.org/]Anonymous
March 29, 2007
PingBack from http://robubu.com/?p=27Anonymous
April 26, 2007
PingBack from http://robubu.com/?p=28Anonymous
September 13, 2007
[Daily Issue] Spiegare il Method In-LiningAnonymous
October 25, 2007
PingBack from http://www.hanselman.com/blog/ReleaseISNOTDebug64bitOptimizationsAndCMethodInliningInReleaseBuildCallStacks.aspxAnonymous
October 25, 2007
Just a reminder: Release builds are not Debug builds. Seems obvious, but it's worth saying again. ReleaseAnonymous
April 29, 2008
Vi builder altid vores release builds med /DEBUG:PDBONLY og /optimize+. Ved at benytte /DEBUG:PDBONLY