Skip to content

Store the dest collection as span to a temp for CopyTo optimization #71270

Open
@RikkiGibson

Description

@RikkiGibson

We removed the span temp for now per #71195 (comment).

We'd like to reintroduce the span temp later, perhaps only when non-async, or when lowering can prove that the span will not be used across an await boundary, or perhaps even reinitializing the span temp when it is used across an await boundary.

This would result in a maybe 2% perf improvement for CopyTo codegen.

T[] result = [..arr1, ..arr2];

// currently becomes
((Span<T>)arr1).CopyTo((Span<T>)result).Slice(...));
((Span<T>)arr2).CopyTo((Span<T>)result).Slice(...));

// we could instead do:
Span<T> spanTemp = result;
((Span<T>)arr1).CopyTo(spanTemp.Slice(...));
((Span<T>)arr2).CopyTo(spanTemp.Slice(...));

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions