title: Properties slower than fields
body: <p>It seems that every post I have come across comes to the same consensus: properties that merely return a field are inlined by JIT and have nearly identical performance to fields.</p>
  
  <p>However, this doesn't seem to be the case with my current scenario. My program does intensive calculations that access many properties that are simply auto-getters and private setters. In this particular case, however, I am just copying an object. </p>
  
  <p>Profiling the code in release mode with optimizations enabled resulted in many calls to the <code>get</code> functions of the property. The calls to <code>Copy()</code> total up to ~5.6ms.</p>
  
  <p><a href="https://i.stack.imgur.com/40fE6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/40fE6.png" alt="Properties benchmark"></a></p>
  
  <p>However, when the properties are converted into fields, the function runs 6x faster than it did with properties:</p>
  
  <p><a href="https://i.stack.imgur.com/vVxG4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vVxG4.png" alt="enter image description here"></a></p>
  
  <p>Comparing equality of two properties seems to incur even more of a performance hit compared to using fields. Here's a benchmark of a class's <code>IEquatable</code> implementation, using the same code but swapping properties with fields.</p>
  
  <p><a href="https://i.stack.imgur.com/IqV6g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IqV6g.png" alt="enter image description here"></a></p>
  
  <p>If JIT is supposed to optimize properties by inlining them, why is this occuring? I would like to keep properties, as the access control aspect of them is very convenient, but if they are this much slower I will stick to fields.</p>
  
  <p><strong>EDIT:</strong> It seems like some (but not all) cases affected by this problem are using properties declared in interfaces. No other polymorphism is being used in these cases, but removing the interface brings the performance variance into expected levels in these cases.</p>
  
  <p><strong>EDIT 2:</strong> As stated in the previous edit, it seems that a part of the problem was due to Interface virtual calls. After more investigation, it seems that running a benchmark in the CLR properly inlines properties, but JetBrains dotTrace does not, even with "Enable inline" checked.</p>