Add benchmark for ImmutableArrayExtensions#4915
Merged
LoopedBard3 merged 6 commits intodotnet:mainfrom Sep 24, 2025
Merged
Conversation
xtqqczze
reviewed
Aug 25, 2025
xtqqczze
reviewed
Aug 25, 2025
src/benchmarks/micro/libraries/System.Linq/ImmutableArrayExtensions.cs
Outdated
Show resolved
Hide resolved
…sions.cs Agreed, adding it. Co-authored-by: xtqqczze <45661989+xtqqczze@users.noreply.github.com>
…sions.cs Co-authored-by: xtqqczze <45661989+xtqqczze@users.noreply.github.com>
Contributor
Author
|
File name changed from |
Member
|
How long does a single operation end up taking? We just want to make sure that we are not in the low nanosecond range. |
Contributor
Author
|
The results themselves are the same as those listed in dotnet/runtime#118932. |
Member
|
I will take a look at this today. |
Contributor
|
I think it would sense to get this in before dotnet/runtime#118932 so we can properly validate the new implementation. |
xtqqczze
reviewed
Aug 28, 2025
src/benchmarks/micro/libraries/System.Linq/Perf.ImmutableArrayExtensions.cs
Outdated
Show resolved
Hide resolved
…Extensions.cs Co-authored-by: xtqqczze <45661989+xtqqczze@users.noreply.github.com>
Contributor
|
@prozolic Please update branch with merge commit to restart CI. |
Contributor
Author
|
@xtqqczze Ok, I've updated the branch. |
Member
|
Looks good and was previously approved. Current failures are unrelated, so merging. |
Contributor
This comment was marked as outdated.
This comment was marked as outdated.
jeffhandley
pushed a commit
to dotnet/runtime
that referenced
this pull request
Feb 16, 2026
# Summary This PR improves the performance of ImmutableArrayExtensions.SequenceEqual method through optimized implementation strategies: Key Performance Improvements: - Array: ~90% faster (68.885ns → 6.856ns) - List: ~91% faster (85.014ns → 7.676ns) - IList: ~54% faster (125.897ns → 57.836ns) - ICollection: No statistically significant performance difference - IEnumerable: Uses existing implementation for this case because the existing implementation had better performance and didn't allocate a second enumerator # Implementation Approach The implementation was refined based on review feedback from @neon-sunset and @xtqqczze to achieve optimal performance while balancing complexity: 1. Fast path for common collections: Detects when items implement `ICollection<T>` and delegates to the highly optimized `Enumerable.SequenceEqual` using the underlying array 2. Compatibility preservation: Falls back to existing implementation for other `IEnumerable<T>` types to maintain behavioral consistency # Benchmark (dotnet/performance#4915) Full benchmark results: [MihuBot/runtime-utils#1565](MihuBot/runtime-utils#1565) (X64) | Method | Toolchain | input | Mean | Error | Ratio | Allocated | Alloc Ratio | |-------------- |---------- |------------ |-----------:|-----------:|------:|----------:|------------:| | SequenceEqual | Main | Array | 68.885 ns | 0.1938 ns | 1.00 | - | NA | | SequenceEqual | PR | Array | 6.856 ns | 0.2262 ns | 0.10 | - | NA | | | | | | | | | | | SequenceEqual | Main | ICollection | 120.542 ns | 7.4864 ns | 1.00 | 32 B | 1.00 | | SequenceEqual | PR | ICollection | 114.458 ns | 1.2362 ns | 0.95 | 32 B | 1.00 | | | | | | | | | | | SequenceEqual | Main | IEnumerable | 121.923 ns | 7.7103 ns | 1.00 | 32 B | 1.00 | | SequenceEqual | PR | IEnumerable | 118.370 ns | 1.4443 ns | 0.98 | 32 B | 1.00 | | | | | | | | | | | SequenceEqual | Main | IList | 125.897 ns | 9.9231 ns | 1.01 | 32 B | 1.00 | | SequenceEqual | PR | IList | 57.836 ns | 0.9568 ns | 0.46 | - | 0.00 | | | | | | | | | | | SequenceEqual | Main | List | 85.014 ns | 1.7593 ns | 1.00 | - | NA | | SequenceEqual | PR | List | 7.676 ns | 0.2719 ns | 0.09 | - | NA | --------- Co-authored-by: Pranav Senthilnathan <pranav.senthilnathan@live.com> Co-authored-by: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Co-authored-by: Pavel Savara <pavel.savara@gmail.com>
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.
Performance benchmark for
ImmutableArrayExtensions.SequenceEqualmethod (related to dotnet/runtime#118932).I have created a new ImmutableArrayExtensions class and added one benchmark. While there are other extension methods for ImmutableArrayExtensions, this implementation focuses only on
ImmutableArrayExtensions.SequenceEqual.