Repository navigation
[Api] Optimize BaggagePropagator - #7059
Closed
martincostello wants to merge 1 commit into
Closed
martincostello wants to merge 1 commit into
martincostello wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7059 +/- ##
==========================================
- Coverage 88.41% 88.36% -0.06%
==========================================
Files 270 270
Lines 12758 12811 +53
==========================================
+ Hits 11280 11320 +40
- Misses 1478 1491 +13
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes OpenTelemetry.Context.Propagation.BaggagePropagator—specifically the Extract() path—by reducing allocations and avoiding LINQ, and adds benchmarks to measure the impact.
Changes:
- Refactored
BaggagePropagator.Extract()/TryExtractBaggage()to avoid LINQ/array materialization and to use span-based parsing on .NET targets. - Added new
BaggagePropagatorbenchmarks to trackExtract/Injectperformance across item counts and encoding scenarios. - Minor benchmark cleanup in
TraceContextPropagatorBenchmarksby switching to a static expression-bodied getter.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/Benchmarks/Context/Propagation/TraceContextPropagatorBenchmarks.cs | Simplifies header getter to a static expression-bodied delegate (avoids capturing/extra code). |
| test/Benchmarks/Context/Propagation/BaggagePropagatorBenchmarks.cs | Adds benchmarks for BaggagePropagator.Extract() and Inject() with configurable sizes/encoding. |
| src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs | Removes LINQ/materialization in Extract and implements span-based parsing in TryExtractBaggage for .NET builds. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
3 of 4 tasks
1 of 4 tasks
- Avoid LINQ. - Use spans where possible.
martincostello
force-pushed
the
optimize-BaggagePropagator
branch
from
April 13, 2026 09:21
9d2892f to
2af5684
Compare
Member
Author
|
Folded into #7061. |
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.
Changes
While looking at some profiles for an OTel instrumented application of mine, I noticed that
BaggagePropagator.Extract()came up in the top 5 OTel-related samples.This makes some improvements by:
Benchmark results
TL;DR:
ExtractatItemCount=5and20(~14–32% faster and ~22–30% less allocated).Injectis mostly stable to slightly better, except forItemCount=1, UseSpecialChars=False- I'm not sure if that's an artifact of the benchmarks or an actual impact of the refactoring.Expand to see
main+ the new benchmarksThis PR
Merge requirement checklist
Unit tests added/updatedAppropriateCHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)