Skip to content

Use OneOrMany for all internal collections #506

@fiseni

Description

@fiseni

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;
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions