Skip to content

[Debugger] Fix Timer leaks and missing rate updates in probe rate limiter#8619

Merged
dudikeleti merged 5 commits into
masterfrom
dudik/fix-probe-rate-limiter
May 15, 2026
Merged

[Debugger] Fix Timer leaks and missing rate updates in probe rate limiter#8619
dudikeleti merged 5 commits into
masterfrom
dudik/fix-probe-rate-limiter

Conversation

@dudikeleti

@dudikeleti dudikeleti commented May 12, 2026

Copy link
Copy Markdown
Contributor

Summary of changes

Fixes Timer/sampler leaks and a latent rate-update bug in ProbeRateLimiter and AdaptiveSampler. AdaptiveSampler allocates a System.Threading.Timer that the runtime roots until disposed; three code paths previously dropped samplers without disposing them, leaking one Timer (plus captured state) on every probe removal and on every dictionary insert race. Separately, RCM-driven rate updates were silently ignored when a sampler already existed.

Reason for change

  • Long-running services using Dynamic Instrumentation accumulate Timer instances on every RCM probe rotation — unbounded growth over the process lifetime.
  • Line probes that go through the unbound → bound transition could end up stuck at the default rate of 1 because CheckUnboundProbes registered the sampler after making the IL live, opening a race window where the first probe hit inserts a default-rate sampler and the configured rate is then dropped by SetRate.

Implementation details

  • IAdaptiveSampler extends IDisposable; AdaptiveSampler.Dispose releases the internal Timer; NopAdaptiveSampler.Dispose is a no-op (singleton).
  • AdaptiveSampler.SetRate mutates _samplesPerWindow / _samplesBudget in place. Uses the same relaxed memory semantics as the rest of the class.
  • ProbeRateLimiter.GerOrAddSampler uses TryGetValueTryAddDispose-on-lose instead of ConcurrentDictionary.GetOrAdd, which can invoke its factory multiple times.
  • ProbeRateLimiter.SetRate applies the new rate to the existing sampler instead of logging and returning; disposes the candidate if it loses the insert race.
  • ProbeRateLimiter.ResetRate disposes the removed sampler.
  • DynamicInstrumentation.CheckUnboundProbes now registers samplers and processors before calling DebuggerNativeMethods.InstrumentProbes, matching the ordering in InstrumentAddedProbes and closing the race at its source.

Test coverage

  • AdaptiveSamplerTestsSetRate updates budget and preserves running stats; Dispose is idempotent.
  • ProbeRateLimiterTests (new) — SetRate updates the existing sampler in place; ResetRate disposes the removed sampler; GerOrAddSampler does not dispose existing entries.

@dudikeleti
dudikeleti marked this pull request as ready for review May 12, 2026 19:19
@dudikeleti
dudikeleti requested a review from a team as a code owner May 12, 2026 19:20

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aa2e1f5eff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tracer/src/Datadog.Trace/Debugger/RateLimiting/ProbeRateLimiter.cs
@pr-commenter

pr-commenter Bot commented May 12, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-05-15 14:50:50

Comparing candidate commit 7cccc0a in PR branch dudik/fix-probe-rate-limiter with baseline commit 3215e62 in branch master.

Some scenarios are present only in baseline or only in candidate runs. If you didn't create or remove some scenarios in your branch, this maybe a sign of crashed benchmarks 💥💥💥
Check Gitlab CI job log to find if any benchmark has crashed.

Scenarios present only in baseline:

  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_RecordException_Sampled net6.0
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_UpdateName_Sampled net6.0
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan netcoreapp3.1
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_GetContext_Sampled net472
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan_SetAttributes_Sampled net472
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan_UpdateName_Sampled netcoreapp3.1
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan net6.0
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan_SetAttributes_Sampled net6.0
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan_SetStatus_Sampled net472
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan_UpdateName_Sampled net6.0
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_RecordException_Sampled netcoreapp3.1
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_SetAttributes_Sampled netcoreapp3.1
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_RecordException_Sampled net472
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_SetStatus_Sampled netcoreapp3.1
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan_GetContext_Sampled net6.0
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan_AddEvent_Sampled netcoreapp3.1
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_AddEvent_Sampled netcoreapp3.1
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_SetStatus_Sampled net472
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan_GetContext_Sampled net472
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_UpdateName_Sampled netcoreapp3.1
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan net6.0
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_SetAttributes_Sampled net472
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan_SetStatus_Sampled netcoreapp3.1
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan_UpdateName_Sampled net472
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_UpdateName_Sampled net472
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan net472
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_AddEvent_Sampled net472
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan_SetAttributes_Sampled netcoreapp3.1
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_GetContext_Sampled net6.0
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan_GetContext_Sampled netcoreapp3.1
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan netcoreapp3.1
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_AddEvent_Sampled net6.0
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_GetContext_Sampled netcoreapp3.1
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan net472
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_SetAttributes_Sampled net6.0
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan_SetStatus_Sampled net6.0
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan_AddEvent_Sampled net472
  • Benchmarks.OpenTelemetry.Api.Trace.ActivityBenchmark.StartSpan_AddEvent_Sampled net6.0
  • Benchmarks.OpenTelemetry.Api.Trace.TelemetrySpanBenchmark.StartSpan_SetStatus_Sampled net6.0

Found 4 performance improvements and 1 performance regressions! Performance is the same for 49 metrics, 18 unstable metrics, 92 known flaky benchmarks, 34 flaky benchmarks without significant changes.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TracerBenchmark.StartActiveSpan net6.0

  • 🟩 allocated_mem [-144 bytes; -143 bytes] or [-9.188%; -9.180%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TracerBenchmark.StartSpan_GetCurrentSpan net6.0

  • 🟩 allocated_mem [-144 bytes; -143 bytes] or [-9.188%; -9.180%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TracerBenchmark.StartSpan_SetActive net6.0

  • 🟩 allocated_mem [-144 bytes; -143 bytes] or [-7.321%; -7.312%]

scenario:Benchmarks.Trace.HttpClientBenchmark.SendAsync net6.0

  • 🟥 throughput [-78795.411op/s; -73022.505op/s] or [-53.527%; -49.605%]

scenario:Benchmarks.Trace.HttpClientBenchmark.SendAsync netcoreapp3.1

  • 🟩 execution_time [-95.313ms; -93.475ms] or [-47.599%; -46.681%]

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan net6.0

  • unstable execution_time [-3.347ms; +34.408ms] or [-2.148%; +22.082%]
  • unstable throughput [-21184.714op/s; +9039.231op/s] or [-13.289%; +5.670%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan netcoreapp3.1

  • unstable execution_time [-57.252ms; -26.559ms] or [-42.752%; -19.832%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_AddEvent_Sampled net6.0

  • unstable execution_time [+31.838ms; +72.252ms] or [+22.410%; +50.855%]
  • unstable throughput [-49999.767op/s; -25641.702op/s] or [-31.671%; -16.242%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_AddEvent_Sampled netcoreapp3.1

  • unstable execution_time [-34.748ms; -9.195ms] or [-31.258%; -8.271%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_GetContext_Sampled net6.0

  • unstable execution_time [-22.159ms; -5.067ms] or [-16.139%; -3.691%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_GetContext_Sampled netcoreapp3.1

  • unstable execution_time [-22.517ms; +13.019ms] or [-20.125%; +11.636%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetAttributes_Sampled net6.0

  • unstable execution_time [-29.512ms; -8.257ms] or [-17.649%; -4.938%]
  • unstable throughput [-1130.337op/s; +11668.744op/s] or [-0.889%; +9.175%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetAttributes_Sampled netcoreapp3.1

  • unstable execution_time [+10.147ms; +35.690ms] or [+11.135%; +39.165%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetStatus_Sampled net6.0

  • unstable execution_time [+3.010ms; +21.193ms] or [+2.431%; +17.120%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetStatus_Sampled netcoreapp3.1

  • unstable execution_time [+7.124ms; +33.529ms] or [+8.051%; +37.890%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_UpdateName_Sampled net6.0

  • unstable execution_time [-38.318ms; -0.729ms] or [-25.010%; -0.476%]
  • unstable throughput [-548.281op/s; +29570.332op/s] or [-0.327%; +17.644%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_UpdateName_Sampled netcoreapp3.1

  • unstable execution_time [-21.094ms; +13.727ms] or [-18.396%; +11.972%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan net6.0

  • 🟩 allocated_mem [-144 bytes; -143 bytes] or [-9.188%; -9.180%]
  • unstable execution_time [-20.579ms; +24.767ms] or [-13.416%; +16.145%]
  • unstable throughput [-17512.081op/s; +11423.023op/s] or [-11.006%; +7.179%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan netcoreapp3.1

  • unstable execution_time [-40.865ms; -1.550ms] or [-30.644%; -1.163%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_AddEvent_Sampled net6.0

  • unstable execution_time [-22.749ms; +3.988ms] or [-14.821%; +2.598%]
  • unstable throughput [-6857.612op/s; +14523.728op/s] or [-5.188%; +10.988%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_AddEvent_Sampled netcoreapp3.1

  • unstable execution_time [-63.125ms; -32.439ms] or [-47.303%; -24.308%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_GetContext_Sampled net6.0

  • 🟥 allocated_mem [+95 bytes; +96 bytes] or [+6.738%; +6.746%]
  • unstable execution_time [-30.499ms; -2.460ms] or [-19.844%; -1.601%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_GetContext_Sampled netcoreapp3.1

  • unstable execution_time [-37.474ms; -12.006ms] or [-33.534%; -10.743%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_RecordException_Sampled net6.0

  • unstable execution_time [-28.686ms; +5.215ms] or [-17.945%; +3.263%]
  • unstable throughput [-8439.116op/s; +16083.081op/s] or [-8.720%; +16.618%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_RecordException_Sampled netcoreapp3.1

  • unstable execution_time [-42.655ms; -2.467ms] or [-32.032%; -1.852%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetAttributes_Sampled net6.0

  • 🟩 execution_time [-50.984ms; -36.297ms] or [-27.404%; -19.509%]
  • 🟩 throughput [+23682.750op/s; +31898.110op/s] or [+24.259%; +32.674%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetAttributes_Sampled netcoreapp3.1

  • unstable execution_time [+3.729ms; +43.088ms] or [+3.350%; +38.717%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetStatus_Sampled net6.0

  • unstable execution_time [+19.862ms; +44.159ms] or [+14.222%; +31.620%]
  • 🟥 throughput [-45693.033op/s; -32808.692op/s] or [-28.847%; -20.713%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetStatus_Sampled netcoreapp3.1

  • unstable execution_time [-34.484ms; -8.448ms] or [-31.406%; -7.694%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_UpdateName_Sampled net6.0

  • unstable execution_time [-3.000ms; +24.772ms] or [-2.107%; +17.395%]
  • unstable throughput [-29117.028op/s; -9633.682op/s] or [-16.935%; -5.603%]

scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_UpdateName_Sampled netcoreapp3.1

  • unstable execution_time [+10.491ms; +34.856ms] or [+11.802%; +39.212%]

scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net472

  • 🟥 throughput [-6375.235op/s; -5723.884op/s] or [-7.559%; -6.787%]

scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net6.0

  • 🟩 execution_time [-81.899ms; -67.065ms] or [-40.859%; -33.459%]
  • 🟥 throughput [-36819.309op/s; -25289.749op/s] or [-30.948%; -21.257%]

scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild netcoreapp3.1

  • 🟩 execution_time [-102.286ms; -100.065ms] or [-51.447%; -50.329%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟥 execution_time [+310.867ms; +326.573ms] or [+154.263%; +162.057%]
  • 🟥 throughput [-56.609op/s; -44.358op/s] or [-10.185%; -7.981%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net6.0

  • 🟥 execution_time [+101.646ms; +103.875ms] or [+80.307%; +82.067%]
  • 🟩 throughput [+75.000op/s; +82.998op/s] or [+9.888%; +10.943%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1

  • 🟥 execution_time [+85.622ms; +86.277ms] or [+75.772%; +76.352%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody net472

  • 🟥 allocated_mem [+1.308KB; +1.308KB] or [+27.528%; +27.540%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody net6.0

  • 🟥 allocated_mem [+439 bytes; +440 bytes] or [+9.299%; +9.310%]
  • unstable execution_time [-51.526ms; -27.634ms] or [-24.064%; -12.906%]
  • unstable throughput [-32101.889op/s; -16702.129op/s] or [-23.433%; -12.192%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody netcoreapp3.1

  • 🟥 allocated_mem [+1.272KB; +1.272KB] or [+27.500%; +27.510%]
  • 🟩 execution_time [-78.402ms; -61.137ms] or [-37.334%; -29.113%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net472

  • 🟥 allocated_mem [+1.307KB; +1.307KB] or [+105.743%; +105.758%]
  • 🟥 throughput [-291074.593op/s; -278183.862op/s] or [-29.720%; -28.404%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net6.0

  • 🟥 allocated_mem [+439 bytes; +440 bytes] or [+35.945%; +35.954%]
  • unstable execution_time [-42.516ms; -15.120ms] or [-18.960%; -6.743%]
  • unstable throughput [-440914.978op/s; -333474.853op/s] or [-47.104%; -35.626%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody netcoreapp3.1

  • 🟥 allocated_mem [+1.272KB; +1.272KB] or [+105.288%; +105.304%]
  • 🟩 execution_time [-86.797ms; -81.921ms] or [-43.325%; -40.891%]
  • 🟥 throughput [-132679.459op/s; -116455.953op/s] or [-19.063%; -16.732%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody net6.0

  • unstable execution_time [-38.713ms; -16.626ms] or [-19.533%; -8.389%]
  • unstable throughput [-26031.655op/s; -9614.033op/s] or [-16.564%; -6.117%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody netcoreapp3.1

  • 🟩 execution_time [-69.012ms; -64.953ms] or [-35.185%; -33.115%]
  • 🟩 throughput [+9170.137op/s; +11815.689op/s] or [+7.305%; +9.413%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody net6.0

  • unstable execution_time [-46.655ms; -26.055ms] or [-23.067%; -12.882%]
  • unstable throughput [-421759.502op/s; -92773.746op/s] or [-14.063%; -3.093%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody netcoreapp3.1

  • 🟩 execution_time [-45.321ms; -24.555ms] or [-20.891%; -11.319%]
  • 🟩 throughput [+171203.578op/s; +226151.035op/s] or [+6.796%; +8.977%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs net472

  • 🟥 execution_time [+301.090ms; +315.633ms] or [+150.445%; +157.711%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs net6.0

  • 🟥 execution_time [+129.702ms; +136.658ms] or [+65.409%; +68.917%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs netcoreapp3.1

  • 🟥 execution_time [+302.767ms; +309.658ms] or [+152.511%; +155.982%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net472

  • 🟥 execution_time [+297.357ms; +311.045ms] or [+146.050%; +152.773%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net6.0

  • 🟥 execution_time [+243.773ms; +259.512ms] or [+119.172%; +126.866%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs netcoreapp3.1

  • 🟥 execution_time [+287.949ms; +300.742ms] or [+143.917%; +150.310%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack net6.0

  • 🟥 execution_time [+22.318µs; +46.236µs] or [+7.125%; +14.761%]
  • 🟥 throughput [-429.378op/s; -228.465op/s] or [-13.385%; -7.122%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net472

  • 🟥 execution_time [+300.193ms; +301.403ms] or [+149.827%; +150.431%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net6.0

  • unstable execution_time [+360.708ms; +373.975ms] or [+391.925%; +406.339%]
  • 🟥 throughput [-6919.234op/s; -6757.798op/s] or [-56.856%; -55.530%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest netcoreapp3.1

  • unstable execution_time [+184.219ms; +248.434ms] or [+139.876%; +188.634%]
  • 🟥 throughput [-1317.838op/s; -1070.918op/s] or [-12.758%; -10.367%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟥 execution_time [+294.791ms; +313.703ms] or [+135.542%; +144.237%]
  • 🟥 throughput [-682.369op/s; -664.066op/s] or [-61.829%; -60.171%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net6.0

  • unstable execution_time [-48.023ms; +85.663ms] or [-20.465%; +36.506%]
  • 🟥 throughput [-693.897op/s; -604.865op/s] or [-46.283%; -40.345%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1

  • 🟥 allocated_mem [+2.305KB; +2.308KB] or [+5.442%; +5.450%]
  • 🟥 execution_time [+345.793ms; +353.825ms] or [+206.824%; +211.628%]
  • 🟥 throughput [-728.916op/s; -694.588op/s] or [-50.753%; -48.363%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice net6.0

  • 🟩 execution_time [-176.138µs; -151.424µs] or [-8.922%; -7.671%]
  • 🟩 throughput [+42.377op/s; +49.933op/s] or [+8.365%; +9.857%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice netcoreapp3.1

  • 🟩 throughput [+12.876op/s; +13.992op/s] or [+5.077%; +5.518%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch net472

  • 🟥 execution_time [+303.654ms; +317.957ms] or [+152.914%; +160.117%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch net6.0

  • unstable execution_time [+180.133ms; +229.353ms] or [+90.265%; +114.929%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch netcoreapp3.1

  • 🟥 execution_time [+302.696ms; +309.338ms] or [+152.062%; +155.398%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net472

  • 🟥 execution_time [+304.547ms; +316.863ms] or [+152.933%; +159.118%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net6.0

  • unstable execution_time [+116.645ms; +180.777ms] or [+57.676%; +89.386%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync netcoreapp3.1

  • 🟥 execution_time [+304.968ms; +312.596ms] or [+154.571%; +158.437%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net472

  • 🟥 execution_time [+304.949ms; +317.576ms] or [+153.057%; +159.395%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net6.0

  • 🟥 execution_time [+307.127ms; +314.579ms] or [+153.075%; +156.789%]
  • 🟩 throughput [+39052.802op/s; +48456.526op/s] or [+7.755%; +9.622%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync netcoreapp3.1

  • 🟥 execution_time [+299.480ms; +305.653ms] or [+148.989%; +152.060%]

scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog net6.0

  • unstable execution_time [-108.634ms; -84.985ms] or [-50.516%; -39.519%]
  • unstable throughput [-62537.617op/s; -22022.790op/s] or [-17.156%; -6.041%]

scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog netcoreapp3.1

  • unstable execution_time [-88.474ms; -65.415ms] or [-44.380%; -32.813%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark net6.0

  • 🟩 allocated_mem [-24.925KB; -24.902KB] or [-9.092%; -9.084%]
  • unstable execution_time [-58.900µs; -1.798µs] or [-11.641%; -0.355%]
  • unstable throughput [+23.048op/s; +227.097op/s] or [+1.150%; +11.332%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark netcoreapp3.1

  • 🟩 allocated_mem [-16.111KB; -16.091KB] or [-5.873%; -5.866%]
  • 🟩 throughput [+97.537op/s; +246.576op/s] or [+5.572%; +14.087%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net472

  • 🟥 allocated_mem [+8.190KB; +8.196KB] or [+16.663%; +16.675%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net6.0

  • unstable execution_time [+2.832µs; +7.259µs] or [+6.693%; +17.158%]
  • 🟥 throughput [-3399.050op/s; -1487.133op/s] or [-14.309%; -6.260%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark netcoreapp3.1

  • unstable execution_time [-12.945µs; -3.473µs] or [-20.084%; -5.388%]
  • unstable throughput [+1072.167op/s; +3052.471op/s] or [+6.578%; +18.728%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net472

  • 🟥 execution_time [+303.156ms; +315.902ms] or [+153.232%; +159.674%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net6.0

  • 🟥 execution_time [+281.215ms; +299.105ms] or [+143.137%; +152.243%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog netcoreapp3.1

  • 🟥 execution_time [+303.101ms; +309.231ms] or [+151.740%; +154.808%]

scenario:Benchmarks.Trace.RedisBenchmark.SendReceive net6.0

  • unstable execution_time [-52.972ms; -12.977ms] or [-26.478%; -6.487%]
  • unstable throughput [-233508.510op/s; -153084.453op/s] or [-44.198%; -28.976%]

scenario:Benchmarks.Trace.RedisBenchmark.SendReceive netcoreapp3.1

  • unstable execution_time [-31.085ms; -5.119ms] or [-15.757%; -2.595%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog net472

  • 🟥 execution_time [+303.462ms; +317.129ms] or [+151.248%; +158.060%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog net6.0

  • unstable execution_time [+259.153ms; +294.738ms] or [+130.134%; +148.003%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog netcoreapp3.1

  • 🟥 execution_time [+303.784ms; +309.247ms] or [+154.060%; +156.830%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net472

  • 🟥 execution_time [+299.985ms; +300.749ms] or [+149.634%; +150.015%]
  • 🟩 throughput [+59699190.253op/s; +59984102.626op/s] or [+43.477%; +43.684%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net6.0

  • 🟥 execution_time [+358.592ms; +366.571ms] or [+445.973%; +455.896%]
  • 🟥 throughput [-7228.029op/s; -7041.356op/s] or [-55.876%; -54.433%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore netcoreapp3.1

  • 🟥 execution_time [+301.580ms; +304.563ms] or [+150.421%; +151.909%]
  • 🟥 throughput [-30390657.089op/s; -29038435.023op/s] or [-13.461%; -12.862%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net6.0

  • unstable execution_time [-79.960ms; -52.322ms] or [-39.163%; -25.626%]
  • unstable throughput [-201115.602op/s; -47646.864op/s] or [-18.778%; -4.449%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope netcoreapp3.1

  • unstable execution_time [-71.901ms; -45.911ms] or [-36.382%; -23.231%]
  • 🟩 throughput [+48615.692op/s; +68663.487op/s] or [+5.627%; +7.948%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan net6.0

  • unstable execution_time [-47.859ms; -23.870ms] or [-24.935%; -12.436%]
  • unstable throughput [-386125.957op/s; -216988.115op/s] or [-29.887%; -16.795%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan netcoreapp3.1

  • unstable execution_time [-74.826ms; -47.445ms] or [-36.763%; -23.311%]
  • 🟩 throughput [+76501.792op/s; +92509.838op/s] or [+7.598%; +9.188%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes net6.0

  • unstable execution_time [-57.449ms; -30.687ms] or [-28.690%; -15.325%]
  • unstable throughput [-154548.843op/s; -75878.081op/s] or [-28.063%; -13.778%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes netcoreapp3.1

  • 🟩 execution_time [-96.267ms; -92.090ms] or [-48.368%; -46.270%]

scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net6.0

  • unstable execution_time [-97.642ms; -71.505ms] or [-48.838%; -35.765%]
  • 🟩 throughput [+62080.332op/s; +84890.843op/s] or [+6.936%; +9.484%]

scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin netcoreapp3.1

  • unstable execution_time [-54.592ms; -26.250ms] or [-27.726%; -13.332%]

Known flaky benchmarks without significant changes:

  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_AddEvent_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_GetContext_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetAttributes_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetStatus_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_UpdateName_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_AddEvent_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_GetContext_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_RecordException_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetAttributes_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetStatus_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_UpdateName_Sampled net472
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody net472
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody net472
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark net472
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark net6.0
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark netcoreapp3.1
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack net472
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net6.0
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net6.0
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice net472
  • scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog net472
  • scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark net472
  • scenario:Benchmarks.Trace.RedisBenchmark.SendReceive net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes net472
  • scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net472

@dudikeleti
dudikeleti requested a review from Copilot May 13, 2026 09:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes resource leaks and a rate-update bug in the debugger probe rate limiting pipeline by ensuring AdaptiveSampler timers are disposed when samplers are dropped, and by applying updated RCM rates to existing samplers rather than ignoring them.

Changes:

  • Make IAdaptiveSampler disposable and dispose AdaptiveSampler’s internal Timer when samplers are removed or lose insertion races.
  • Update ProbeRateLimiter to (a) avoid ConcurrentDictionary.GetOrAdd factory double-invocation leaks and (b) apply rate updates in-place on existing samplers.
  • Close an instrumentation race by registering processors/samplers before activating IL for newly-bound probes.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tracer/src/Datadog.Trace/Debugger/RateLimiting/IAdaptiveSampler.cs Extends the sampler contract to IDisposable so implementations can release resources.
tracer/src/Datadog.Trace/Debugger/RateLimiting/AdaptiveSampler.cs Adds Dispose() for timer cleanup and SetRate() to mutate rate-related fields in place.
tracer/src/Datadog.Trace/Debugger/RateLimiting/NopAdaptiveSampler.cs Implements no-op Dispose() to satisfy IAdaptiveSampler : IDisposable.
tracer/src/Datadog.Trace/Debugger/RateLimiting/ProbeRateLimiter.cs Reworks sampler add/update/remove logic to avoid leaks and ensure rate updates are applied.
tracer/src/Datadog.Trace/Debugger/DynamicInstrumentation.cs Adjusts ordering in CheckUnboundProbes to prevent default-rate sampler races.
tracer/test/Datadog.Trace.Tests/Debugger/AdaptiveSamplerTests.cs Adds tests for SetRate behavior and idempotent Dispose.
tracer/test/Datadog.Trace.Tests/Debugger/ProbeRateLimiterTests.cs Adds new tests covering rate updates, disposal on removal, and GerOrAddSampler behavior.
tracer/test/Datadog.Trace.Tests/Debugger/ProbeProcessorTests.cs Updates test sampler stub to implement Dispose() per new interface.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tracer/src/Datadog.Trace/Debugger/RateLimiting/ProbeRateLimiter.cs Outdated
Comment thread tracer/test/Datadog.Trace.Tests/Debugger/ProbeRateLimiterTests.cs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@dd-trace-dotnet-ci-bot

dd-trace-dotnet-ci-bot Bot commented May 13, 2026

Copy link
Copy Markdown

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (8619) and master.

✅ No regressions detected - check the details below

Full Metrics Comparison

FakeDbCommand

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration72.35 ± (72.64 - 73.23) ms72.53 ± (72.65 - 73.08) ms+0.3%✅⬆️
.NET Framework 4.8 - Bailout
duration76.54 ± (76.59 - 77.01) ms76.81 ± (76.75 - 77.17) ms+0.4%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1104.05 ± (1102.66 - 1109.13) ms1105.95 ± (1106.12 - 1115.72) ms+0.2%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms22.38 ± (22.34 - 22.42) ms22.47 ± (22.42 - 22.51) ms+0.4%✅⬆️
process.time_to_main_ms83.78 ± (83.60 - 83.95) ms83.68 ± (83.50 - 83.87) ms-0.1%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.91 ± (10.91 - 10.92) MB10.93 ± (10.93 - 10.94) MB+0.2%✅⬆️
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms22.70 ± (22.64 - 22.75) ms22.70 ± (22.65 - 22.75) ms+0.0%✅⬆️
process.time_to_main_ms88.07 ± (87.72 - 88.42) ms87.94 ± (87.60 - 88.29) ms-0.1%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.95 ± (10.94 - 10.95) MB10.96 ± (10.96 - 10.97) MB+0.2%✅⬆️
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms212.39 ± (211.27 - 213.51) ms211.76 ± (210.90 - 212.62) ms-0.3%
process.time_to_main_ms534.72 ± (533.32 - 536.13) ms536.21 ± (534.84 - 537.57) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.40 ± (48.37 - 48.43) MB48.52 ± (48.48 - 48.56) MB+0.2%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.2%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms21.66 ± (21.60 - 21.73) ms21.50 ± (21.44 - 21.56) ms-0.8%
process.time_to_main_ms76.06 ± (75.75 - 76.37) ms75.16 ± (74.88 - 75.44) ms-1.2%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.62 ± (10.61 - 10.62) MB10.66 ± (10.66 - 10.66) MB+0.4%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms21.33 ± (21.29 - 21.37) ms21.11 ± (21.08 - 21.15) ms-1.0%
process.time_to_main_ms75.23 ± (75.05 - 75.40) ms74.22 ± (74.05 - 74.39) ms-1.3%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.73 ± (10.73 - 10.74) MB10.77 ± (10.77 - 10.77) MB+0.3%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms377.04 ± (374.96 - 379.11) ms373.93 ± (371.60 - 376.26) ms-0.8%
process.time_to_main_ms538.11 ± (536.85 - 539.37) ms539.82 ± (538.22 - 541.43) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed49.91 ± (49.88 - 49.94) MB49.88 ± (49.85 - 49.91) MB-0.1%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.1%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms19.35 ± (19.32 - 19.38) ms19.34 ± (19.29 - 19.39) ms-0.1%
process.time_to_main_ms72.02 ± (71.85 - 72.19) ms72.92 ± (72.65 - 73.20) ms+1.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.67 ± (7.67 - 7.68) MB7.68 ± (7.67 - 7.69) MB+0.1%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms19.77 ± (19.71 - 19.82) ms19.63 ± (19.57 - 19.68) ms-0.7%
process.time_to_main_ms75.96 ± (75.67 - 76.25) ms75.65 ± (75.38 - 75.92) ms-0.4%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.73 ± (7.72 - 7.73) MB7.72 ± (7.72 - 7.73) MB-0.1%
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms294.91 ± (292.53 - 297.29) ms292.74 ± (290.57 - 294.92) ms-0.7%
process.time_to_main_ms493.99 ± (492.93 - 495.05) ms499.00 ± (497.49 - 500.51) ms+1.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.91 ± (36.88 - 36.93) MB36.91 ± (36.88 - 36.94) MB+0.0%✅⬆️
runtime.dotnet.threads.count27 ± (27 - 27)27 ± (27 - 27)+0.0%

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration198.97 ± (198.36 - 199.30) ms199.51 ± (199.45 - 200.49) ms+0.3%✅⬆️
.NET Framework 4.8 - Bailout
duration202.92 ± (202.28 - 203.20) ms202.47 ± (202.21 - 203.23) ms-0.2%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1195.70 ± (1196.39 - 1202.13) ms1199.41 ± (1206.95 - 1217.32) ms+0.3%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms195.39 ± (194.87 - 195.90) ms194.84 ± (194.36 - 195.31) ms-0.3%
process.time_to_main_ms84.31 ± (84.03 - 84.58) ms83.87 ± (83.61 - 84.12) ms-0.5%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.05 ± (16.03 - 16.08) MB16.05 ± (16.02 - 16.07) MB-0.1%
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)+0.5%✅⬆️
.NET Core 3.1 - Bailout
process.internal_duration_ms195.10 ± (194.59 - 195.61) ms193.80 ± (193.29 - 194.31) ms-0.7%
process.time_to_main_ms85.44 ± (85.16 - 85.72) ms84.82 ± (84.56 - 85.07) ms-0.7%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.06 ± (16.04 - 16.08) MB16.04 ± (16.02 - 16.06) MB-0.1%
runtime.dotnet.threads.count21 ± (21 - 21)21 ± (21 - 21)+0.1%✅⬆️
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms391.20 ± (389.64 - 392.77) ms386.51 ± (385.28 - 387.75) ms-1.2%
process.time_to_main_ms532.42 ± (531.46 - 533.39) ms532.72 ± (531.46 - 533.99) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed57.78 ± (57.55 - 58.01) MB57.40 ± (57.21 - 57.59) MB-0.7%
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (30 - 30)+0.1%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms198.81 ± (198.32 - 199.30) ms198.82 ± (198.35 - 199.29) ms+0.0%✅⬆️
process.time_to_main_ms72.78 ± (72.50 - 73.07) ms72.43 ± (72.19 - 72.67) ms-0.5%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.21 ± (16.19 - 16.24) MB16.35 ± (16.33 - 16.37) MB+0.8%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)+0.1%✅⬆️
.NET 6 - Bailout
process.internal_duration_ms198.58 ± (198.22 - 198.93) ms196.46 ± (195.99 - 196.92) ms-1.1%
process.time_to_main_ms73.74 ± (73.56 - 73.92) ms72.99 ± (72.74 - 73.24) ms-1.0%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.31 ± (16.28 - 16.34) MB16.42 ± (16.39 - 16.45) MB+0.7%✅⬆️
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)-1.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms594.03 ± (591.36 - 596.71) ms591.65 ± (588.96 - 594.34) ms-0.4%
process.time_to_main_ms533.30 ± (532.45 - 534.15) ms533.10 ± (532.12 - 534.09) ms-0.0%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed61.34 ± (61.24 - 61.44) MB61.28 ± (61.17 - 61.38) MB-0.1%
runtime.dotnet.threads.count31 ± (31 - 31)31 ± (31 - 31)+0.2%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms196.52 ± (195.95 - 197.09) ms196.79 ± (196.33 - 197.25) ms+0.1%✅⬆️
process.time_to_main_ms72.03 ± (71.79 - 72.28) ms72.14 ± (71.88 - 72.40) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.70 ± (11.68 - 11.72) MB11.70 ± (11.68 - 11.72) MB+0.0%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)-0.4%
.NET 8 - Bailout
process.internal_duration_ms195.59 ± (195.01 - 196.17) ms196.04 ± (195.67 - 196.42) ms+0.2%✅⬆️
process.time_to_main_ms72.93 ± (72.68 - 73.18) ms73.40 ± (73.21 - 73.59) ms+0.6%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.74 ± (11.72 - 11.75) MB11.76 ± (11.74 - 11.78) MB+0.2%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)-0.4%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms515.59 ± (513.35 - 517.84) ms512.67 ± (510.39 - 514.95) ms-0.6%
process.time_to_main_ms491.63 ± (490.86 - 492.40) ms491.37 ± (490.54 - 492.20) ms-0.1%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed50.55 ± (50.52 - 50.59) MB50.55 ± (50.51 - 50.58) MB-0.0%
runtime.dotnet.threads.count30 ± (29 - 30)30 ± (29 - 30)+0.0%✅⬆️
Comparison explanation

Execution-time benchmarks measure the whole time it takes to execute a program, and are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are highlighted in **red**. The following thresholds were used for comparing the execution times:

  • Welch test with statistical test for significance of 5%
  • Only results indicating a difference greater than 5% and 5 ms are considered.

Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard.

Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph).

Duration charts
FakeDbCommand (.NET Framework 4.8)
gantt
    title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8619) - mean (73ms)  : 70, 76
    master - mean (73ms)  : 68, 77

    section Bailout
    This PR (8619) - mean (77ms)  : 74, 80
    master - mean (77ms)  : 74, 80

    section CallTarget+Inlining+NGEN
    This PR (8619) - mean (1,111ms)  : 1038, 1184
    master - mean (1,106ms)  : 1059, 1153

Loading
FakeDbCommand (.NET Core 3.1)
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8619) - mean (113ms)  : 110, 116
    master - mean (113ms)  : 109, 116

    section Bailout
    This PR (8619) - mean (118ms)  : 112, 124
    master - mean (118ms)  : 110, 126

    section CallTarget+Inlining+NGEN
    This PR (8619) - mean (785ms)  : 758, 812
    master - mean (785ms)  : 758, 812

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8619) - mean (103ms)  : 97, 110
    master - mean (104ms)  : 98, 110

    section Bailout
    This PR (8619) - mean (102ms)  : 99, 104
    master - mean (103ms)  : 99, 107

    section CallTarget+Inlining+NGEN
    This PR (8619) - mean (941ms)  : 886, 997
    master - mean (944ms)  : 901, 987

Loading
FakeDbCommand (.NET 8)
gantt
    title Execution time (ms) FakeDbCommand (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8619) - mean (100ms)  : 95, 106
    master - mean (99ms)  : 96, 102

    section Bailout
    This PR (8619) - mean (103ms)  : 98, 109
    master - mean (104ms)  : 98, 110

    section CallTarget+Inlining+NGEN
    This PR (8619) - mean (825ms)  : 778, 871
    master - mean (821ms)  : 786, 856

Loading
HttpMessageHandler (.NET Framework 4.8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8619) - mean (200ms)  : 193, 207
    master - mean (199ms)  : 192, 205

    section Bailout
    This PR (8619) - mean (203ms)  : 195, 210
    master - mean (203ms)  : 198, 207

    section CallTarget+Inlining+NGEN
    This PR (8619) - mean (1,212ms)  : 1131, 1294
    master - mean (1,199ms)  : 1157, 1241

Loading
HttpMessageHandler (.NET Core 3.1)
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8619) - mean (288ms)  : 281, 295
    master - mean (289ms)  : 282, 296

    section Bailout
    This PR (8619) - mean (288ms)  : 279, 297
    master - mean (289ms)  : 282, 296

    section CallTarget+Inlining+NGEN
    This PR (8619) - mean (957ms)  : 935, 979
    master - mean (964ms)  : 940, 988

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8619) - mean (280ms)  : 269, 290
    master - mean (280ms)  : 273, 288

    section Bailout
    This PR (8619) - mean (278ms)  : 272, 284
    master - mean (281ms)  : 276, 286

    section CallTarget+Inlining+NGEN
    This PR (8619) - mean (1,156ms)  : 1116, 1196
    master - mean (1,156ms)  : 1120, 1193

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8619) - mean (279ms)  : 271, 287
    master - mean (279ms)  : 273, 285

    section Bailout
    This PR (8619) - mean (280ms)  : 275, 284
    master - mean (279ms)  : 271, 286

    section CallTarget+Inlining+NGEN
    This PR (8619) - mean (1,036ms)  : 999, 1073
    master - mean (1,039ms)  : 1003, 1076

Loading

@dudikeleti
dudikeleti enabled auto-merge (squash) May 13, 2026 15:13
Comment on lines +153 to +156
// Plain writes match the rest of the class's relaxed memory model; rate change is
// visible "eventually" and self-corrects on the next window roll.
_samplesPerWindow = samplesPerWindow;
_samplesBudget = samplesPerWindow + ((long)_budgetLookback * samplesPerWindow);

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.

I haven't look deep into the algorithm, but I am scared that it may happen to have incoherent values between the 2 fields while processing the sampling leading to errors like exceptions.
Why not recreating an instance of AdaptiveSampler when changing the rate? should not be that frequent.

@dudikeleti dudikeleti May 15, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't replace because ProbeData caches the sampler reference, so replacing the dictionary entry would not update existing probe data. I have a task in the pipeline to fix this, and then we’ll be able to handle it correctly.

For now, I thought it would be better to keep it relaxed temporarily, but you’re right about the concern. I added synchronization around the rare SetRate/RollWindow paths and atomic budget access while keeping Sample() lock-free.

7cccc0a

dudikeleti and others added 5 commits May 15, 2026 15:18
…iter

AdaptiveSampler owns a System.Threading.Timer that the runtime roots in its
global timer queue until disposed. Three paths in the dynamic-instrumentation
rate limiter dropped samplers without disposing them, so over the lifetime of
a process every probe removal, every RCM-driven rate-update race, and every
GerOrAddSampler race against an RCM update would leak a Timer plus the
captured callback graph.

This commit:

- Makes IAdaptiveSampler implement IDisposable so callers can dispose any
  sampler implementation uniformly (NopAdaptiveSampler's Dispose is a no-op
  since it is a singleton).
- Implements AdaptiveSampler.Dispose to release the timer.
- Adds AdaptiveSampler.SetRate to mutate _samplesPerWindow / _samplesBudget
  in place, preserving the running EMAs and probability. Re-creating the
  sampler on rate updates (the previously suggested fix) would have wiped
  history and caused a transient sampling spike on every RCM rate change.
  Memory ordering matches the rest of the class, which is intentionally
  relaxed on the hot path.
- ProbeRateLimiter.GerOrAddSampler now uses TryGetValue + TryAdd + Dispose
  on race-loss instead of ConcurrentDictionary.GetOrAdd, which can invoke
  its factory multiple times and silently drop the losing AdaptiveSampler
  (and its Timer).
- ProbeRateLimiter.SetRate now applies the new rate to the existing sampler
  via AdaptiveSampler.SetRate instead of logging "already exist" and
  ignoring the update; also disposes the candidate sampler when it loses
  the insert race.
- ProbeRateLimiter.ResetRate now disposes the removed sampler, fixing the
  leak that was triggered on every RCM probe removal.

Adds AdaptiveSamplerTests for SetRate (budget update + history preservation)
and Dispose (idempotent), plus a new ProbeRateLimiterTests suite covering
SetRate in-place update, ResetRate disposal, and GerOrAddSampler no-leak
behavior.

Co-authored-by: Cursor <[email protected]>
When a previously-unbound line probe is resolved, DynamicInstrumentation.
CheckUnboundProbes was calling DebuggerNativeMethods.InstrumentProbes
before AddProbeProcessor / SetRateLimit. A probe hit in the window between
those two calls would land in GerOrAddSampler, which inserts a default-rate
sampler; the subsequent SetRateLimit would then see the existing entry and
the user-configured rate would never take effect for that probe.

Mirror the ordering used by InstrumentAddedProbes: register the processor
and rate limiter for each newly-bound probe first, then make the IL live.

Also tighten the inline comments that came in with the previous commit.

Co-authored-by: Cursor <[email protected]>
@dudikeleti
dudikeleti force-pushed the dudik/fix-probe-rate-limiter branch from 40544e0 to 7cccc0a Compare May 15, 2026 13:45
@dudikeleti
dudikeleti merged commit ee13f56 into master May 15, 2026
140 of 141 checks passed
@dudikeleti
dudikeleti deleted the dudik/fix-probe-rate-limiter branch May 15, 2026 16:00
@github-actions github-actions Bot added this to the vNext-v3 milestone May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants