Skip to content

[Exporter.Prometheus] Improve UTF-8 escaping performance - #7758

Merged
martincostello merged 3 commits into
open-telemetry:mainfrom
martincostello:improve-prometheus-escaping
Sep 18, 2026
Merged

martincostello merged 3 commits into
open-telemetry:mainfrom
martincostello:improve-prometheus-escaping

Conversation

@martincostello

@martincostello martincostello commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Changes

Improve the performance of escaping UTF-8 values during serialization to be O(n) instead of O(n^2) when targeting modern .NET.

Benchmarks

Case Before After Delta
NonAsciiLong (~3.6k chars) 86.4 µs 16.0 µs ~5.4x faster
AsciiLong (~980 chars) 166 ns 90 ns ~1.8x faster
NonAsciiShort (~18 chars) 75.7 ns 106.8 ns within noise
AsciiShort (~11 chars) 10.8 ns 19.6 ns within noise
Allocated (all cases) 0 B 0 B no change

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)

Improve the performance of escaping UTF-8 values during serialization to be `O(n)` instead of `O(n^2)` when targeting modern .NET.
Comment thread src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md Outdated
Comment thread src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md Outdated
@codecov

codecov Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.85%. Comparing base (6ee4b19) to head (20606e5).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7758      +/-   ##
==========================================
- Coverage   91.87%   91.85%   -0.03%     
==========================================
  Files         339      339              
  Lines       18468    18469       +1     
==========================================
- Hits        16967    16964       -3     
- Misses       1501     1505       +4     
Flag Coverage Δ
unittests-Project-Experimental 91.94% <100.00%> (-0.05%) ⬇️
unittests-Project-Stable 91.96% <100.00%> (-0.05%) ⬇️
unittests-UnstableCoreLibraries-Experimental 50.48% <100.00%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
...ernal/Shared/Serialization/TextFormatSerializer.cs 98.71% <100.00%> (+<0.01%) ⬆️

... and 3 files with indirect coverage changes

@github-actions github-actions Bot added pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package labels Sep 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The performance claim needs before-and-after benchmark results.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Optimizes shared Prometheus UTF-8 escaping by scanning input once.

Changes:

  • Replaces dual searches with one verbatim-character search.
  • Documents the optimization for both exporter packages.
File summaries
File Description
TextFormatSerializer.cs Implements linear escaping scan.
HttpListener CHANGELOG.md Records the optimization.
AspNetCore CHANGELOG.md Records the shared optimization.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@martincostello
martincostello marked this pull request as ready for review September 16, 2026 15:39
@martincostello
martincostello requested a review from a team as a code owner September 16, 2026 15:39
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-09-18 10:16 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

This was referenced Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants