The method used by List.Sort ends up using Array.Sort which generates 2 bytes of garbage even if you pass in an instance for IComparer. I need to sort many lists every frame in Unity3d so I need an algorithm that will not create a single byte of garbage if possible. Stack allocation for temporary variables should be fine.
if (comparer == null)
comparer = (IComparer<T>)Comparer<T>.Default;
if (BinaryCompatibility.TargetsAtLeast_Desktop_V4_5)
ArraySortHelper<T>.IntrospectiveSort(keys, index, length, comparer);
else
ArraySortHelper<T>.DepthLimitedQuickSort(keys, index, length + index - 1, comparer, 32);