title: Will C#-JIT implement "inline virtual method" optimizations with future versions in inspiration of Java?
body: <p>Or should I consider refactoring my virtual indexing method(and its class) into a code-duplicated but faster one?</p>
  
  <p>The issue I'm stuck at, I had some duplicated code, then refactored them and unified into a single class with just single virtual method in child classes only to minimize future code duplications. Now its %50 slower than before to accomplish this:</p>
  
  <pre><code> arr[i]=3.14f; // arr is derived from a base class with `[]` override
   (so the derived class implementation is used).
  </code></pre>
  
  <p>but it became %500 easier to add new types now.</p>
  
  <p>How many if-else checks in a non-virtual method makes it equally fast as a virtual one without if-else checks inside?(for todays 20-30 length pipelined cpus) float+char+double+some other structs = there would be more than 15 different types in my library so 15x code duplication would make the code %1500 harder to implement/refactor without virtual methods.</p>
  
  <hr>
  
  <p>Example of my issue:</p>
  
  <pre><code>// implemented IList because C# arrays instead of this, 
  // can be used in same wrapper property too! 
  // Reduced even more code duplication.
  public class Foo&lt;T&gt;:IList&lt;T&gt;
  {
      public virtual T this [int i]
      { ... }
  }
  
  public unsafe class Bar:Foo&lt;byte&gt;
  {
      public override byte this[int i]
      {
              get
              {
                 return *(pByte + i);
              }
              set
              {
                 *(pByte + i) = value;
              }
           }
      }
   }
  
   Bar b=new Bar(); // Can't use Foo&lt;byte&gt; 
   // because I denied that with making its constructor `internal`
   // because its mis-use would generate undefined behaviour(more than an out-of-bounds  access) in a random time in a random place.
  
   b[400]=50;
  </code></pre>
  
  <hr>
  
  <p>The reason I have to duplicate code without <code>virtual</code> is, no pointer is allowed for <code>T</code> generic types. </p>
  
  <hr>
  
  <p>The reason I have to use pointers is, I have non-managed fast gpgpu C++ arrays to be worked likes just as same as pure C# when looked from outside.</p>
  
  <hr>
  
  <p>The reason I had to use unmanaged arrays for gpgpu is, they work at top speed when they are aligned to unobtainable values like 4096 and needed to be pinned and also to reduce C# - C++ transition overheads.</p>
  
  <hr>
  
  <p>Note: maybe it is not only virtual, but also the <code>IList&lt;T&gt;</code> interface contributing to slowness. Many answers say <code>it comes with a cost</code> but if Java can work around it, why can't C#? </p>
  
  <p>Here is the environment:</p>
  
  <ul>
  <li>.Net 3.5</li>
  <li>MSVS 2015 community ed. all optimizations enabled.</li>
  <li>windows 10 64 bit</li>
  <li>project 64 bit release</li>
  <li>c3060 cpu with a single channel ddr3 ram</li>
  <li>for benchmarking, heating phase is added, timings are taken after many iterations and used in real data visualizations.</li>
  </ul>