Skip to content

Reduce tracing allocations before sampling and during UTF-8 context parsing #96

Closed

Description

@thomhurst

Follow-up to the allocation findings in the Claude review of PR #94: #94 (comment).

In src/Relayer/Telemetry/MessageOperationTracing.cs, Start copies constant tags into an ActivityTagsCollection and copies batch links (or allocates a single-link array) before the sampler decides whether to record an activity. A listener that drops every span still pays those allocations. In src/Relayer/Telemetry/MessageCreationContext.cs, Read decodes a UTF-8 traceparent into a string for ActivityContext.TryParse; native UTF-16 values already reuse their existing string through WireString.ToString.

The no-listener budget remains defined by D25 and design §8.5/§12. This work also removes avoidable preparation allocations with enabled tracing. The required sampler attributes are those listed in design §8.3; creation links must remain visible to samplers. Other message attributes can be added after all activity data is requested.

Acceptance criteria:

  • Extend the MemoryDiagnoser tracing benchmarks to cover a sampler returning None, a single creation link, borrowed batch links, and UTF-8 context parsing with and without tracestate. Record diagnostic baseline and candidate results outside the repository.
  • Reduce pre-sampling tag/link allocations where possible without removing the design §8.3 sampling attributes or creation links, changing parent/link rules, retaining borrowed buffers after Start, or trading throughput/latency/CPU against allocations without maintainer approval.
  • Reduce UTF-8 traceparent materialization using span-based parsing if measurements support it. Preserve the framework parser's W3C validation/version behavior, remote flag, tracestate, and byte-for-byte immutable header behavior. Do not add header decoding allocations for native UTF-16 values. ActivityContext stores its trace/span IDs as strings, so even the framework UTF-16 parser allocates that context storage (144 B on the measured .NET 10 runtime).
  • Add regression tests for dropped spans, sampler-visible attributes/links, and valid/invalid UTF-8 and UTF-16 context inputs.
  • Keep context reads on demand when integrating Integrate tracing into direct single and batch sends #92/Integrate process and settlement tracing into delivery pipelines #93; propagation must still work without a local tracing listener. Do not gate required propagation solely on HasListeners.

Own the tracing primitives, dedicated tracing tests, and tracing benchmarks. This is separate from automatic send/process integration in #92 and #93 and belongs to the #13 telemetry work.

Activity

  1. added
    phase-0: core
    area: telemetry
    area: performance
    P3
    on Nov 1, 2026
  2. added
    in-progress
    on Nov 1, 2026
  3. thomhurst commented on Nov 1, 2026

    @thomhurst
    OwnerAuthor

    The follow-up is now implemented in PR #94 at 0856989, including sampler-visible partition attributes and creation links, reusable preparation storage, UTF-8 parsing, regression tests, and side-by-side MemoryDiagnoser comparisons. The PR carries Closes #96; this issue remains open until it merges.

    The acceptance criteria now name design §8.3's required sampling attributes and distinguish header materialization from the framework's own trace/span ID strings. Measured ActivityContext storage costs 144 B on .NET 10, even with native UTF-16 headers. Final UTF-8 parsing removes the additional 136 B header string and has lower default-job mean times. Final dropped sampling cases allocate 0 B; recorded-send timing is unchanged within Short-run noise. Evidence and the verified SHA-256 inventory are linked in the PR body.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area: performancearea: telemetryin-progressphase-0: core

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions