Skip to content

Add a feature flag to not use GVM in Linq Select #109978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/libraries/System.Linq/src/System/Linq/Select.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,19 @@ public static IEnumerable<TResult> Select<TSource, TResult>(

if (source is Iterator<TSource> iterator)
{
return iterator.Select(selector);
// With native AOT, calling into the `Select` generic virtual method results in NxM
// expansion of native code. If the option is enabled, we don't call the generic virtual
// for value types. We don't do the same for reference types because reference type
// expansion can happen lazily at runtime and the AOT compiler does postpone it (we
// don't need more code, just more data structures describing the new types).
if (IsSizeOptimized && typeof(TResult).IsValueType)
{
return new IEnumerableSelectIterator<TSource, TResult>(iterator, selector);
}
else
{
return iterator.Select(selector);
}
}

if (source is IList<TSource> ilist)
Expand Down