Skip to content

[DNM] Performance improvements#7062

Closed
martincostello wants to merge 25 commits intoopen-telemetry:mainfrom
martincostello:performance-improvements
Closed

[DNM] Performance improvements#7062
martincostello wants to merge 25 commits intoopen-telemetry:mainfrom
martincostello:performance-improvements

Conversation

@martincostello
Copy link
Copy Markdown
Member

Changes

Combines the changes from the following PRs so I can get a single set of NuGet packages from CI to test:

Not intended for review or to be merged.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

martincostello and others added 25 commits April 10, 2026 14:06
Add support for GZip compression to the OTLP exporter.

Picks up from open-telemetry#6494.

Resolves open-telemetry#3961.

Co-Authored-By: Hannah Haering <157852144+hannahhaering@users.noreply.github.com>
Pool `SuppressInstrumentationScope` instances to avoid allocations.
Add `[MemoryDiagnoser]` to `SuppressInstrumentationScope` benchmarks.
Optimize `SamplingResult` for cases when there are no attributes to avoid allocating an enumerator and add benchmarks.
- Avoid allocating a buffer for every write of compressed gRPC data.
- Simplify `IsTransientNetworkError()`.
Add coverage for different ways to specify the compression value.
The benchmark doesn't call the method directly, so it can stay private.
Remove inaccurate comment.
- Reduce the size of the pool.
- Avoid over-eager stack allocation.
- Use a singleton `NoOpDisposable`.
- Prevent disposing stale references.
- Add more tests.
- Ensure only one `grpc-encoding` header.
- Remove redundant null checks.
Add benchmarks for `BaggagePropagator`.
- Avoid LINQ.
- Use spans where possible.
Refactor based on suggestions from Copilot to improve throughput and reduce allocations by avoiding LINQ.
Extend test coverage for `TraceContextPropagator`.
Address Copilot code review feedback.
Add test that appears to relate to GHSA-8785-wc3w-h8q6, although it passes before and after that change was reverted.
Fix-up the regression test so it actually detects the issue caused by open-telemetry#5749.
@github-actions github-actions Bot added pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package perf Performance related labels Apr 12, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 12, 2026

Codecov Report

❌ Patch coverage is 93.29073% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.49%. Comparing base (feb588b) to head (9ebb662).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
....Api/Context/Propagation/TraceContextPropagator.cs 90.05% 17 Missing ⚠️
src/OpenTelemetry/Trace/TracerProviderSdk.cs 69.23% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7062      +/-   ##
==========================================
+ Coverage   88.39%   88.49%   +0.09%     
==========================================
  Files         270      270              
  Lines       12758    12993     +235     
==========================================
+ Hits        11278    11498     +220     
- Misses       1480     1495      +15     
Flag Coverage Δ
unittests-Project-Experimental 88.26% <93.29%> (-0.09%) ⬇️
unittests-Project-Stable 88.19% <93.29%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...metry.Api/Context/Propagation/BaggagePropagator.cs 87.80% <100.00%> (+1.65%) ⬆️
...ol/Implementation/ExportClient/OtlpExportClient.cs 97.33% <100.00%> (+0.15%) ⬆️
...mplementation/ExportClient/OtlpGrpcExportClient.cs 78.76% <100.00%> (+4.29%) ⬆️
...mplementation/ExportClient/OtlpHttpExportClient.cs 93.54% <100.00%> (+3.54%) ⬆️
...orter.OpenTelemetryProtocol/OtlpExporterOptions.cs 99.37% <100.00%> (+0.09%) ⬆️
src/OpenTelemetry/SuppressInstrumentationScope.cs 93.65% <100.00%> (+3.17%) ⬆️
src/OpenTelemetry/Trace/Sampler/SamplingResult.cs 100.00% <100.00%> (ø)
src/OpenTelemetry/Trace/TracerProviderSdk.cs 98.09% <69.23%> (-1.26%) ⬇️
....Api/Context/Propagation/TraceContextPropagator.cs 89.35% <90.05%> (-1.05%) ⬇️

... and 4 files with indirect coverage changes

@martincostello
Copy link
Copy Markdown
Member Author

Initial net summary of comparing the changes from this PR from a Grafana k6 run for martincostello/costellobot@4e92338 vs. martincostello/costellobot@a9c505c.

Differences:

  • CPU:
    • Changes to export - expected as GZip compression was enabled
    • Less time spent:
      • Processing trace/context propagation
      • Processing baggage
      • Sampling activities
      • Starting the ASP.NET Core activity
    • No more calls to SuppressInstrumentationScope.IsSuppressed
  • Allocations:
    • ~50% fewer allocations for baggage propagation
    • Increased HTTP export allocations due to GZip compression

CPU

Before

image

After

image

Allocations

Before

image

After

image

@martincostello
Copy link
Copy Markdown
Member Author

There's also visible allocation reductions in my app's benchmarks:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf Performance related pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant