My question is why does the C# compiler not allow inlining of the C# MSIL functions. I'm aware the JIT will inline the actual X86 assembly in some cases but I'm asking about the actual MSIL "assembly" code.
Why does the C# compiler not offer these types of optimisation?
Is it because there would be minimal to no gain? Or it simply has never been implemented?
The responses to a similar question for the Java compiler's optimizations when translating to JVM bytecode seem to be applicable. A compiler from a high-level language (C# or Java) to an intermediate language (CIL/MSIL or JVM bytecode) might not want to optimize its emitted code because:
Eric Lippert's blog post on the C# compiler's /optimize
flag supports the notion that the compiler prefers to do less optimization, leaving it for the .NET JIT:
These are very straightforward optimizations; there’s no inlining of IL, no loop unrolling, no interprocedural analysis whatsoever. We let the jitter team worry about optimizing the heck out of the code when it is actually spit into machine code; that’s the place where you can get real wins.