Madhawa Learns To Blog

.net, c#, sql, OOAD and more mad memory dumps...

Tuesday, May 17, 2005

How compiler decides a method to inline or not?

When I’m dipping into improving performance of managed code I got wondered how compiler decides a method to inline or not.

Ok, First I’ll tell you what is method inlining (to whom, think what’s the hell is this inlining).

As all we know 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.
But if your virtual method is sealed its candidates for inlining as well as other compiler optimizations also.
• 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 or while.)
• 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.


But note on, those things might be change in future versions of the JIT.
And other thing, don’t compromise the correctness of the method to attempt to guarantee that it will be inlined.
Pretty interesting? ha

2 Comments:

At 2:52 PM , Blogger Andrew K said...

This is some gud stuff i've read in weeks, keep up da gud work bro. 'cos it's lot easier to go through the extracts of sumthin than the whole article.

 
At 2:56 PM , Blogger Madhawa said...

:) thx ma man, there r lot of things to post wut I'm researching but i'm damn busy these days.

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home