Skip to content

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

@Flash0ver

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETPull requests that update .net codePerformance

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions