Skip to content

perf: Avoid shallow copies of DSC when sample_rate or replay_id are overwritten #4381

Closed

Description

@Flash0ver

Description

So far, the Dynamic Sampling Context (DSC) was immutable after the first propagation.

But in the meantime, immutability only partially applies, after

For both cases, we allocate a shallow copy of the DynamicSamplingContext instance, and the underlying IReadOnlyDictionary.
Since DynamicSamplingContext is an internal class, we can optimize the implementation details to avoid copy allocations, and instead mutate the internal Dictionary that we create in the .ctor.

Alternatively, we could rewrite or derive a DynamicSamplingContext, and/or introduce something similar like a DynamicSamplingContextBuilder. But since the DynamicSamplingContext is internal this may not be required.

Activity

  1. added a commit that references this issue on Aug 20, 2025
    e9b3962
  2. added a commit that references this issue on Aug 27, 2025
    a542f0c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

.NETPull requests that update .net codePerformance

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions