jamescourtney / FlatSharp

Fast, idiomatic C# implementation of Flatbuffers
Apache License 2.0
511 stars 51 forks source link

[Performance] Devirtualize IList Vectors #130

Closed jamescourtney closed 3 years ago

jamescourtney commented 3 years ago

IList<T> is implemented by many different classes:

Some of these, such as T[] are special and can observe large performance gains when using the type directly, but suffer the virtual method penalty when exposed through the IList<T> interface.

Devirtualization would look like:

public void ListOp<T>(IList<T> list)
{
     if (list is T[] array)
     {
         {array-loop}
     }
     else if (list is List<T> realList)
     {
        {list-loop}
     }
     else
     {
         {ilist-loop}
     }
}

This issue tracks the work necessary to investigate:

jamescourtney commented 3 years ago

Published in version 5.2