-
Notifications
You must be signed in to change notification settings - Fork 5k
Add whitespace handling methods to MemoryExtensions #111439
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
base: main
Are you sure you want to change the base?
Conversation
Updated the MemoryExtensions class with new methods for efficient whitespace handling, including ContainsAnyWhiteSpace, IndexOfAnyWhiteSpace, and LastIndexOfAnyWhiteSpace. Optimized the IsWhiteSpace method to utilize SearchValues.WhiteSpaces. Added corresponding test cases in StringSearchValues.cs to validate the new functionality.
Note regarding the
|
1 similar comment
Note regarding the
|
Tagging subscribers to this area: @dotnet/area-system-memory |
src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A concern we had with the implementation here was whether it's worth paying the overhead of taking a vectorized path if we expect the match to commonly be close to the start.
For example it's not obvious why span.IsWhiteSpace
should use a different strategy compared to string.IsNullOrWhiteSpace
, where the 99% case is that you're validating an argument and expect it have non-whitespace chars (often already with the first character).
Have you done any perf measurements for such cases?
src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com>
I haven't conducted performance measurements for such cases yet, but I’d be happy to write and run performance tests if we can determine the most relevant data set for the evaluation. Could you clarify what types of inputs or scenarios would best reflect the use cases you're concerned about? For example, should we focus on inputs where the match is typically close to the start, or would you like a broader range of cases? Your guidance will help ensure the tests provide meaningful insights. |
I write benchmarks for the ROSpan IsWhiteSpace method. On my computer, I got the next results
|
src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs
Outdated
Show resolved
Hide resolved
`string.SearchValuesStorage.WhiteSpaceChars` in the `MemoryExtensions` class methods.
This commit removes the `using System.Buffers;` directive from the `MemoryExtensions.Globalization.cs` file, indicating that the functionality provided by the `System.Buffers` namespace is no longer needed or has been replaced by alternative implementations.
Part of #77959 except
ContainsAnyExceptWhiteSpace
Updated the MemoryExtensions class with new methods for efficient whitespace handling, including ContainsAnyWhiteSpace, IndexOfAnyWhiteSpace, and LastIndexOfAnyWhiteSpace.
Optimized the IsWhiteSpace method to utilize SearchValues.WhiteSpaces.
Added corresponding test cases in StringSearchValues.cs to validate the new functionality.