Skip to content

Special-case collection expressions of ImmutableArray of 1-4 elements #85793

Description

@DoctorKrolic

ImmutableArray<T> already has special treatment in collection expressions world, e.g. [] is lowered as ImmutableArray<T>.Empty. However, construction of an array of 1-4 elements, which is most common in practice, creates an array and then wraps it into an immutable array via ImmutableCollectionsMarshal.AsImmutableArray(array). From performance point of view this is totally fine since we allocate the resulting array only once, but from the IL size point we can do better and use predefined ImmutableArray.Create factory methods, which exist for creating arrays of 1-4 elements without params array or any other overhead. This is a super trivial change that won't require much work

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions