[perf] Add fast path for unescaped W3C baggage - #134647
Open
martincostello wants to merge 2 commits into
Open
martincostello wants to merge 2 commits into
martincostello wants to merge 2 commits into
Conversation
Mirror `EncodeBaggageValue()` by adding a fast path for baggage values that do not need percent decoding.
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @steveisok, @dotnet/area-system-diagnostics-tracing |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The fast path redundantly scans conforming values twice, undermining its marginal performance benefit.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Adds a .NET-only fast path for unescaped ASCII W3C baggage values.
Changes:
- Returns plain ASCII baggage directly without using
ValueStringBuilder. - Retains existing decoding for escaped or non-ASCII values.
| File | Description |
|---|---|
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/W3CPropagator.cs |
Adds the baggage-decoding fast path. |
Do a single scan with `IndexOfAnyExcept()`.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The optimization preserves existing behavior, uses the established character set, has existing functional coverage, and includes benchmark evidence.
Review effort: Balanced
Findings: None
Resolved since last review (1)
martincostello
marked this pull request as ready for review
September 25, 2026 11:14
This branch has not been deployed
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.

Mirror
EncodeBaggageValue()by adding a fast path for baggage values that do not need percent decoding.Benchmarks
vs. main: plain (common case) ~9% faster, allocation unchanged (a string must be produced
either way). Escaped (uncommon case): within noise across repeated runs (bounced between -4%
and +3%), versus a consistent ~+5% before this change.
Benchmark code