This is another micro-optimization we can do to reduce the size of the specifications.
We keep the internal state as List<> (e,g, Where, Order, Include, etc). However, consumers most commonly have a single clause in the specs, single Where with Order, and other combinations. We should optimize for this use case. The overhead of a non-empty List is 88 bytes, and it's a waste for cases where we store a single item.
We may create a struct OneOrMany<T> with a single object? state, and then treat the state as T or List<T> based on the situation. By default, we'll use only 8 bytes (on x64) for the reference, and that's the same cost we pay now for the List<>? reference.
internal struct OneOrMany<T>
{
private object? _value;
}
This is another micro-optimization we can do to reduce the size of the specifications.
We keep the internal state as
List<>(e,g,Where,Order,Include, etc). However, consumers most commonly have a single clause in the specs, singleWherewithOrder, and other combinations. We should optimize for this use case. The overhead of a non-emptyListis 88 bytes, and it's a waste for cases where we store a single item.We may create a struct
OneOrMany<T>with a singleobject?state, and then treat the state asTorList<T>based on the situation. By default, we'll use only 8 bytes (on x64) for the reference, and that's the same cost we pay now for theList<>?reference.