Skip to content

[Exporter.Geneva] Reduce per-record allocations - #4498

Merged
Kielek merged 3 commits into
open-telemetry:mainfrom
petrroll:geneva-sanitize-cache
Jun 24, 2026
Merged

Kielek merged 3 commits into
open-telemetry:mainfrom
petrroll:geneva-sanitize-cache

Conversation

@petrroll

@petrroll petrroll commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Cut hot-path allocations in the Geneva exporter:

  • Cache sanitized logger category names with a lock-free copy-on-write (CAS) cache, plus an accelerated fast path that returns the original string when it is already a valid event name. The cache snapshot is a FrozenDictionary on .NET 8+ and a Dictionary elsewhere.
  • MetricSerializer.SerializeBase128String now writes UTF-8 directly into the buffer via GetByteCount/GetBytes instead of allocating a temp byte[] and copying.
  • MsgPackTraceExporter.SerializeHttpUrl writes the composed HTTP url segments straight into the msgpack buffer (back-patching the STR16 header) instead of building interpolated strings + StringBuilder; the rare >16383-char case still delegates to GetHttpUrl for byte-identical truncation.

Adds byte-for-byte equivalence tests for SerializeHttpUrl and before/after allocation benchmarks for each optimization.

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)

@petrroll
petrroll requested a review from a team as a code owner June 11, 2026 10:24
@github-actions github-actions Bot added comp:exporter.geneva Things related to OpenTelemetry.Exporter.Geneva perf Performance related labels Jun 11, 2026
@martincostello martincostello changed the title Reduce per-record allocations in Geneva exporter [Exporter.Geneva] Reduce per-record allocations Jun 11, 2026

@martincostello martincostello left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks reasonable to me.

Are there any changes that could/should be made to extend the fuzz tests?

@petrroll
petrroll force-pushed the geneva-sanitize-cache branch 2 times, most recently from e241260 to 327d240 Compare June 11, 2026 16:12
@codecov

codecov Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.53571% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.17%. Comparing base (6f85636) to head (20e24c8).
⚠️ Report is 33 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...metry.Exporter.Geneva/Internal/Tld/TldLogCommon.cs 94.64% 3 Missing ⚠️
...eva/Internal/EventHeader/EventHeaderLogExporter.cs 0.00% 1 Missing ⚠️
...try.Exporter.Geneva/Internal/Tld/TldLogExporter.cs 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4498      +/-   ##
==========================================
+ Coverage   75.93%   76.17%   +0.23%     
==========================================
  Files         439      439              
  Lines       18050    18114      +64     
==========================================
+ Hits        13707    13799      +92     
+ Misses       4343     4315      -28     
Flag Coverage Δ
unittests-Exporter.Geneva 56.37% <95.53%> (+0.94%) ⬆️

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

Files with missing lines Coverage Δ
...er.Geneva/Internal/MsgPack/MsgPackTraceExporter.cs 94.87% <100.00%> (+0.67%) ⬆️
...emetry.Exporter.Geneva/Metrics/MetricSerializer.cs 100.00% <100.00%> (ø)
...eva/Internal/EventHeader/EventHeaderLogExporter.cs 14.08% <0.00%> (ø)
...try.Exporter.Geneva/Internal/Tld/TldLogExporter.cs 18.75% <0.00%> (ø)
...metry.Exporter.Geneva/Internal/Tld/TldLogCommon.cs 66.41% <94.64%> (+46.84%) ⬆️

... and 12 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@martincostello martincostello left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks reasonable to me but I defer to the component owners for final approval.

@martincostello

Copy link
Copy Markdown
Member

Needs some style fixes too.

@petrroll
petrroll force-pushed the geneva-sanitize-cache branch from 327d240 to 7a6b93c Compare June 11, 2026 17:24
Cut hot-path allocations in the Geneva exporter:

* Cache sanitized logger category names with a lock-free copy-on-write
  (CAS) cache, plus an accelerated fast path that returns the original
  string when it is already a valid event name. The cache snapshot is a
  FrozenDictionary on .NET 8+ and a Dictionary elsewhere.
* MetricSerializer.SerializeBase128String now writes UTF-8 directly into
  the buffer via GetByteCount/GetBytes instead of allocating a temp byte[]
  and copying.
* MsgPackTraceExporter.SerializeHttpUrl writes the composed HTTP url
  segments straight into the msgpack buffer (back-patching the STR16
  header) instead of building interpolated strings + StringBuilder; the
  rare >16383-char case still delegates to GetHttpUrl for byte-identical
  truncation.

Adds byte-for-byte equivalence tests for SerializeHttpUrl and before/after
allocation benchmarks for each optimization.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@petrroll
petrroll force-pushed the geneva-sanitize-cache branch from 7a6b93c to c786f40 Compare June 11, 2026 17:28
@petrroll

Copy link
Copy Markdown
Contributor Author

Adjusted

@rajkumar-rangaraj rajkumar-rangaraj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@xiang17 Could you please review before the merge?

@github-actions

Copy link
Copy Markdown
Contributor

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions Bot added the Stale label Jun 24, 2026
@martincostello martincostello added keep-open Prevents issues and pull requests being closed as stale and removed Stale labels Jun 24, 2026
@Kielek
Kielek added this pull request to the merge queue Jun 24, 2026
Merged via the queue into open-telemetry:main with commit 0e0be35 Jun 24, 2026
80 checks passed
This was referenced Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:exporter.geneva Things related to OpenTelemetry.Exporter.Geneva perf Performance related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants