[Exporter.Prometheus] Improve performance

Merged
MA
4mo ago
+389-112

Changes

Improve the performance of PrometheusSerializer by:

  • Using SearchValues<T> on .NET 8+
  • Writing common label value types directly instead of relying on ToString()
  • Formatting numeric values directly as UTF-8 on .NET 8+
  • Caching serialized metric names, metadata names, units, and static tag prefixes
  • Reusing serialized tags across histogram bucket/sum/count output

See https://github.com/open-telemetry/opentelemetry-dotnet/pull/7279#issuecomment-4624820224 for results.

Supersedes #7170.

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)