Skip to content

Reduce ETW span export allocations - #4761

Open
lalitb wants to merge 7 commits into
open-telemetry:mainfrom
lalitb:perf/etw-span-allocations
Open

lalitb wants to merge 7 commits into
open-telemetry:mainfrom
lalitb:perf/etw-span-allocations

Conversation

@lalitb

@lalitb lalitb commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Reduce ETW span allocations by avoiding attribute copies and using local inline storage for generated fields. Speed up timestamp formatting while preserving payload representation, field ordering, and custom field-name behavior. No new configuration options or dependencies.

Benchmark: main vs PR

Full span lifecycle, including active Scope and cleanup, with real enabled ETW writes on Windows x64. Main: 0a5bb0b; PR: a1b8205.

Attributes Activity tracking Main PR Time reduction
0 Off 9.500 us 6.282 us 34%
3 Off 10.899 us 7.002 us 36%
0 On 15.223 us 11.006 us 28%
3 On 17.689 us 12.403 us 30%

Medians of batch averages; shared-VM results vary. Tradeoff: measured warm stack usage increases from about 3.0 KB to 3.5 KB.

Validation: 91 ETW tests, five Windows Bazel targets, C++14 payload-parity checks, and zero capture loss.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lalitb
lalitb requested a balanced review from Copilot November 2, 2026 21:48
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

In the affected MsgPack configuration, _time is stored only in a temporary map, so the final Span write regenerates it and can emit a timestamp different from the Stop event’s value.

1 open issue
What changed in this PR

This PR reduces allocations and copying in the header-only ETW span export path while retaining owned properties for environment-property encoding and materializing properties for MessagePack.

Changes:

  • Borrow span attributes and merge generated fields in sorted order for TLD encoding.
  • Remove an extra attribute copy, reuse matching ID strings, and reserve initial encoding-buffer capacity.
  • Add tests for attribute ownership, merged ordering, override precedence, and ID reuse and repair.
File Description
exporters/​etw/​test/​etw_tracer_test.cc Tests attribute ownership, self-assignment, and ID reuse and repair.
exporters/​etw/​test/​etw_properties_test.cc Tests borrowed properties, sorted merging, overrides, and empty inputs.
exporters/​etw/​include/​opentelemetry/​exporters/​etw/​etw_tracer.h Uses borrowed span-end properties and avoids redundant attribute and ID copies.
exporters/​etw/​include/​opentelemetry/​exporters/​etw/​etw_provider.h Supports merged property encoding, MessagePack materialization, and buffer reservations.
exporters/​etw/​include/​opentelemetry/​exporters/​etw/​etw_properties.h Adds a borrowed property view with owned overrides and materialization.

Review effort: Balanced

@codecov

codecov Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.62%. Comparing base (0a5bb0b) to head (941c9a7).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4761   +/-   ##
=======================================
  Coverage   86.62%   86.62%           
=======================================
  Files         530      530           
  Lines       21169    21169           
=======================================
  Hits        18335    18335           
  Misses       2834     2834           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

lalitb and others added 4 commits November 2, 2026 14:31
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reuse bounded generated-field nodes for untracked TLD span export, co-allocate spans, and avoid unnecessary parent lookup and temporary values. Preserve timestamp bytes with fixed-width formatting and cover payload parity, reentrancy, parent selection, and timestamp edge cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fall back to local properties after the thread-local cache is destroyed. Cover unfinished thread-local span destruction with a worker-thread regression, use C++11-compatible aligned byte storage, and document the generated-field overwrite invariant.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep up to eleven owning generated entries in local storage, sort before each write, and preserve complete map semantics on overflow. Share span emission/status logic with the owned MessagePack and environment-property paths. Repair IDs against the effective generated-or-saved value, including custom field-name collisions. Cover payload parity, optional fields, reentrancy, overflow and thread exit, with CMake and Bazel registrations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the ETW exporter allocation and formatting optimizations.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Remove the accidental public access label introduced during the inline-field refactor. Keep the implementation and benchmarked runtime paths unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lalitb
lalitb marked this pull request as ready for review November 3, 2026 23:58
@lalitb
lalitb requested a review from a team as a code owner November 3, 2026 23:58

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants