IList<T> is implemented by many different classes:
T[]
List<T>
FlatBufferVector<T>
ReadOnlyCollection<T>
Custom implementations
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:
Which well known IList<T> implementations have substantial performance gains when the underlying type is used directly? Probably T[] and List<T>, but anything else?
What is the penalty for devirtualization via the is operator? How expensive are these comparisons?
Is there a length threshold at which this becomes (un)profitable?
What is the code size impact? ie, does the increase in binary size come with an increase in performance?
IList<T>
is implemented by many different classes:T[]
List<T>
FlatBufferVector<T>
ReadOnlyCollection<T>
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 theIList<T>
interface.Devirtualization would look like:
This issue tracks the work necessary to investigate:
IList<T>
implementations have substantial performance gains when the underlying type is used directly? ProbablyT[]
andList<T>
, but anything else?is
operator? How expensive are these comparisons?