This node became pretty intransparent in terms of memory management, we just had many GC2 collections because this node can now use a SpreadBuilder
as input.
The problem seems to be this code, which basically only avoids a copy for MutableArray
, Spread
, and ImmutableArray
(almost never in use). So this should rather change into an adaptive implementation which will get red when an unsupported collection is connected or at least trigger a warning or have an output pin that informs the user that the data is copied and show the user a list of collections that work without a copy:
public static bool TryGetArray<T>(this IEnumerable<T> sequence, out T[] array)
{
if (sequence is T[] _array)
{
array = _array;
return true;
}
else if (sequence is Spread<T> spread)
{
array = spread.GetInternalArray();
return true;
}
else if (sequence is ImmutableArray<T> immutableArray)
{
array = Unsafe.As<ImmutableArray<T>, T[]>(ref immutableArray);
return true;
}
else
{
array = default;
return false;
}
}
The idea of supporting more collections is definitely good, but then also the name should change and just be called InstancingComponent
or so. And as is very likely that it deals with big memory chunks the memory behavior should be transparent.