Skip to content

Remove forced inlining from Span<T>.ToArray - #132635

Merged
jkotas merged 2 commits into
dotnet:mainfrom
LE0-Lin:perf-span-toarray-inlining-119713
Aug 24, 2026
Merged

jkotas merged 2 commits into
dotnet:mainfrom
LE0-Lin:perf-span-toarray-inlining-119713

Conversation

@LE0-Lin

@LE0-Lin LE0-Lin commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #119713.

Summary

Span<T>.ToArray() is currently marked with AggressiveInlining, while
ReadOnlySpan<T>.ToArray() is not.

This change removes the forced-inlining hint from Span<T>.ToArray() and
allows the JIT to make its normal profitability decision.

Rationale

Existing JIT-diff experiments discussed in #119713 evaluated both ways of
making the two implementations consistent.

Adding AggressiveInlining to ReadOnlySpan<T>.ToArray() resulted in
substantially more code-size churn, including multiple regressions.

By comparison, removing AggressiveInlining from Span<T>.ToArray() had a
much smaller code-size impact.

Given that ToArray() allocates and does not necessarily benefit from being
forcibly inlined at every call site, removing the hint is the more conservative
way to make the implementations consistent.

The runtime behavior of ToArray() is unchanged.

Validation

The code change is limited to removing the AggressiveInlining attribute.

The JIT-diff experiments referenced in the issue discussion are:

Credit to @xtqqczze for running the JIT-diff experiments used to evaluate the
tradeoff.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Aug 21, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

@jkotas

jkotas commented Aug 21, 2026

Copy link
Copy Markdown
Member

Could you please also apply ImmutableArray simplifications that were noticed during investigation of this issue #119713 (comment) ?

@LE0-Lin
LE0-Lin force-pushed the perf-span-toarray-inlining-119713 branch from b607656 to 10f7f4f Compare August 22, 2026 00:51
@LE0-Lin
LE0-Lin force-pushed the perf-span-toarray-inlining-119713 branch from 10f7f4f to c870d73 Compare August 22, 2026 00:52
@MichalPetryka

Copy link
Copy Markdown
Contributor

@MihuBot -nuget

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@jkotas

jkotas commented Aug 24, 2026

Copy link
Copy Markdown
Member

/ba-g infrastructure timeouts

@jkotas jkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@jkotas
jkotas merged commit 868c06a into dotnet:main Aug 24, 2026
125 of 127 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Aug 24, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Runtime community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent inlining between Span.ToArray and ReadOnlySpan.ToArray

3 participants