1

Say we have a class with a simple property :

public string MyProperty
{
    get { return _myProperty; }
    set { _myProperty = value; }
}

This property is a good candidate for inlining using directly the backing field. But if this is done inside an other assembly and then the setter/getter are changed, the behaviour would not be forwarded to the calling assembly. In the other hand, if the inlining is not performed I am filling that we are lacking a lot...

Maybe the inlining is performed at the CLR level? Also, do you have any links explaining inlining? (how a method is choosen for in-lining, the algorithm and the other optimizations perfomed ...) I did not find any real useful documentation as of now on Google.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Toto
  • 7,491
  • 18
  • 50
  • 72
  • One of the advantages of the .NET runtime compilation model is the ability to inline across assemblies. – Ben Voigt Jul 29 '14 at 01:43
  • This is one reason that this kind of inlining is handled by the JIT compiler and not by the C# compiler. – Mike Zboray Jul 29 '14 at 02:06
  • @mikez do you have some link explaining how it works at the JIT level ? – Toto Jul 29 '14 at 02:12
  • 1
    AFAIK the rules for how a method is chosen for inlining are not documented. There are several blog posts by .NET Framework developers (examples [here](http://blogs.msdn.com/b/vancem/archive/2008/08/19/to-inline-or-not-to-inline-that-is-the-question.aspx), [here](http://blogs.msdn.com/b/davidnotario/archive/2004/11/01/250398.aspx)) at various times describing some of the details, but these are subject to change. I will note that currently the x64 jitter is completely different from the x86 jitter. Also Microsoft is working on a new version of the JIT for the next major framework release. – Mike Zboray Jul 29 '14 at 02:24
  • @mikez given all your rseponses and the links, the inlining really happens at the JIT level. Is this only happens here, do you have some documentation on that ? – Toto Jul 29 '14 at 02:48
  • The C# spec says "Exposing state through properties is not necessarily any less efficient than exposing fields directly. In particular, when a property is non-virtual and contains only a small amount of code, the execution environment may replace calls to accessors with the actual code of the accessors. This process is known as **inlining**, and it makes property access as efficient as field access, yet preserves the increased flexibility of properties." and leaves it at that. – Mike Zboray Jul 29 '14 at 02:58
  • Otherwise, all I have to go on is comments by the compiler developers like [this](http://stackoverflow.com/questions/1343019/if-optimizations-are-enabled-will-the-jit-always-inline-this-method#comment1178664_1343019). – Mike Zboray Jul 29 '14 at 02:58

0 Answers0