Add back MinInteger/MaxInteger paths for IEnumerables in LINQ#130138
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-memory |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reintroduces specialized Min/Max fast paths in System.Linq.Enumerable for non-span IEnumerable<T> inputs when T is an integer type and the caller uses the default comparer (or null comparer), avoiding per-element Comparer<T>.Default.Compare overhead.
Changes:
- Added
MinIntegerEnumerator<T>/MaxIntegerEnumerator<T>helpers that compute min/max via direct</>comparisons forIBinaryInteger<T>types. - Updated the generic
Min<TSource>(IEnumerable<TSource>, IComparer<TSource>?)andMax<TSource>(...)implementations to detect common integer types and route to the new enumerator helpers when the comparer is default or null.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/libraries/System.Linq/src/System/Linq/Min.cs | Adds an integer enumerator-based min helper and routes the generic Min<TSource> to it for non-span integer sequences with default/null comparer. |
| src/libraries/System.Linq/src/System/Linq/Max.cs | Adds an integer enumerator-based max helper and routes the generic Max<TSource> to it for non-span integer sequences with default/null comparer. |
tannergooding
approved these changes
Jul 2, 2026
MihaZupan
enabled auto-merge (squash)
July 2, 2026 18:46
eiriktsarpalis
pushed a commit
that referenced
this pull request
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #130047 - perf regression from #128306 for
IEnumerableinputs where we can't extract the span, and theTis an integer type. #128306 removed the loop that'll go over theIEnumerableand compare results via<instead of going throughIComparer. This PR adds that logic back.MihuBot/runtime-utils#2066
The intention before merging that PR was to avoid such regressions, but looks like my benchmark in #128306 (comment) didn't catch it EgorBot/Benchmarks#208 (comment).