Polyfill SearchValues and optimize Activity, W3CPropagator#119673
Merged
MihaZupan merged 4 commits intodotnet:mainfrom Oct 10, 2025
Merged
Polyfill SearchValues and optimize Activity, W3CPropagator#119673MihaZupan merged 4 commits intodotnet:mainfrom
MihaZupan merged 4 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds polyfills for modern .NET APIs like SearchValues to enable optimization of string searching operations across different target frameworks. The key change is replacing many manual character-by-character validation loops and character array lookups with more efficient SearchValues operations.
Key changes:
- Adds polyfill infrastructure for
SearchValues<char>,Ascii.IsValid, and span extension methods for downlevel targets - Optimizes W3CPropagator by replacing bitmask-based validation with SearchValues and simplifying trace parent validation logic
- Converts various libraries to use SearchValues instead of IndexOfAny with character arrays or manual loops
Reviewed Changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/libraries/Directory.Build.targets |
Adds MSBuild logic to include polyfill files when IncludeSpanPolyfills is enabled |
src/libraries/Common/src/System/Text/AsciiPolyfills.cs |
Polyfill implementation of Ascii.IsValid methods for downlevel targets |
src/libraries/Common/src/System/MemoryExtensionsPolyfills.cs |
Polyfill for ContainsAnyExcept span extension method |
src/libraries/Common/src/System/Buffers/SearchValuesPolyfills.cs |
Complete polyfill implementation of SearchValues APIs using bitmap for ASCII chars |
| Multiple library projects | Enable polyfills and convert to use SearchValues instead of manual validation loops |
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/W3CPropagator.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexParser.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/W3CPropagator.cs
Show resolved
Hide resolved
xtqqczze
reviewed
Sep 13, 2025
f823ab1 to
6ab683b
Compare
Contributor
|
Tagging subscribers to this area: @dotnet/area-meta |
cea32e2 to
190cb7d
Compare
xtqqczze
reviewed
Sep 21, 2025
src/libraries/System.Reflection.Metadata/src/System.Reflection.Metadata.csproj
Show resolved
Hide resolved
stephentoub
approved these changes
Oct 10, 2025
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/W3CPropagator.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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Polyfilling such helpers seems like a neat way of avoiding duplication in a bunch of places where we might want to use newer APIs.
W3cPropagatorbeing an extreme example where we were already duplicating a bunch of logic, but still not usingSearchValueseverywhere because it would add even more.Benchmark source