Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes string.Split(char, ...) by adding a dedicated fast path for the most common scenario: splitting on a single separator character, including a new vectorized implementation for scanning separator positions.
Changes:
- Added a single-separator (
separators.Length == 1) specialized path inMakeSeparatorListAny. - Introduced a new
MakeSeparatorListVectorized(..., char c)overload to vectorize scanning for a single separator char. - Adjusted the existing 2–3 separator path to assume
separators.Length >= 2(since the 1-separator case is now handled earlier).
This comment was marked as resolved.
This comment was marked as resolved.
Contributor
Author
…or non-existent, which is similar to what IndexOf does
This comment was marked as outdated.
This comment was marked as outdated.
src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs
Outdated
Show resolved
Hide resolved
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This was referenced Mar 10, 2026
Open
Contributor
Author
src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs
Outdated
Show resolved
Hide resolved
This comment was marked as resolved.
This comment was marked as resolved.
6 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/libraries/System.Private.CoreLib/src/System/SpanHelpers.Packed.cs:1147
- These PackSources helpers were made internal to support new callers outside PackedSpanHelpers, but the file-level comment indicates this type exists to hide "private helpers". Consider updating the nearby commentary / documenting the intended usage constraints (e.g., only call when the relevant ISA is supported and CanUsePackedIndexOf has been validated) to avoid future misuse within the assembly.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[CompExactlyDependsOn(typeof(Avx512BW))]
internal static Vector512<byte> PackSources(Vector512<short> source0, Vector512<short> source1)
{
Debug.Assert(Avx512BW.IsSupported);
// Pack two vectors of characters into bytes. While the type is Vector256<short>, these are really UInt16 characters.
// X86: Downcast every character using saturation.
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/String.SplitTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/String.SplitTests.cs
Show resolved
Hide resolved
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.



In some cases
string.Split(char, ...)was slower (significantly) than the singlestringseperator overload - this PR optimizes thecharoverload/s to have much closer performance (still a small gap in 1 case) - the single-charoverloads are the most common case, so I have added the additional optimisation just for that for now - benchmarks below.Main benchmark that was the focus - single char splitter with rare/no seperators (17% improvement on arm, 47% improvement on x64) -
charalmost matches or outperformsstringnow (could probably get it to match by adjusting the branches carefully - I can implement if wanted, but it will probably make it less readable):X64 (AMD):

Arm:

Other cases have not regressed meaningfully (within margin of error) - some have even possibly improved slightly on x64: EgorBot/Benchmarks#28