Some time ago I read the .NET 3.5 Service Pack 1 would bring some nice improvements in the JIT compiler for the x86. Among them there were some modifications regarding how the JIT inlines methods (see my previous post about Inline Methods).
Today I’ve seen this post from Vance Morrison where describes the heuristic used to determine when a candidate method must be inlined or not. Which according to him looks like follows:
“1. Estimate the size of the call site if the method were not inlined.
2. Estimate the size of the call site if it were inlined (this is an estimate based on the IL, we employ a simple state machine (Markov Model), created using lots of real data to form this estimator logic)
3. Compute a multiplier. By default it is 1
4. Increase the multiplier if the code is in a loop (the current heuristic bumps it to 5 in a loop)
5. Increase the multiplier if it looks like struct optimizations will kick in.
6. If InlineSize <= NonInlineSize * Multiplier do the inlining.”
I invite you to read the entire post, I’ve found it very interesting.