Add fast path in string.Concat#130361
Merged
Merged
Conversation
This PR adds a fast path for string.Concat when the input value is List<string?> or string?[]. This fast path is based on the pattern already used in Join(string? separator, IEnumerable<string?> values). I have also added tests for the fast path and fallback path.
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-runtime |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the System.String.Concat(IEnumerable<string?> values) overload in System.Private.CoreLib by adding type-specialized fast paths for common inputs (arrays and List<T>), and extends existing String.Concat tests to cover these additional enumerable shapes.
Changes:
- Add a fast path for
List<string?>inputs by extracting a span viaCollectionsMarshal.AsSpanand forwarding to the span-basedConcatimplementation. - Add a fast path for
string?[]inputs by forwarding to the span-basedConcatimplementation. - Extend
StringTests.Concat_Stringto validate results for a non-array/non-list enumerable (LINQSelect) and for aList<string?>.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs | Adds List/array fast paths for Concat(IEnumerable<string?>) by forwarding to span-based concat. |
| src/libraries/Common/tests/Tests/System/StringTests.cs | Adds test coverage for the new fast-path inputs and a fallback enumerable shape. |
prozolic
marked this pull request as ready for review
July 8, 2026 14:20
MihaZupan
reviewed
Jul 8, 2026
…ation.cs Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com>
MihaZupan
approved these changes
Jul 8, 2026
Member
|
Thanks |
This was referenced Jul 9, 2026
Contributor
Author
|
@MihaZupan CI seems to be failing due to a timeout. Could you check the current status? |
Contributor
Author
|
Thank you! |
eiriktsarpalis
pushed a commit
that referenced
this pull request
Jul 15, 2026
Co-authored-by: Miha Zupan <mihazupan.zupan1@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.
This PR adds a fast path for
string.Concat(IEnumerable<string?> values)when the input value isList<string?>orstring?[]. This fast path is based on the pattern already used inJoin(string? separator, IEnumerable<string?> values).I have also added tests for the fast path and fallback path.
Benchmark
This Change is expected to improve performance when the argument of
string.Concat(IEnumerable<string?> values)isList<string?>orstring?[].