Skip to content

More remote config performance improvements#8241

Merged
andrewlock merged 11 commits into
masterfrom
andrew/remote-config/perf
Mar 11, 2026
Merged

More remote config performance improvements#8241
andrewlock merged 11 commits into
masterfrom
andrew/remote-config/perf

Conversation

@andrewlock

Copy link
Copy Markdown
Member

Summary of changes

A variety of minor performance improvements to remote config

Reason for change

I did some initial benchmarking of remote config, as well as running a test app with ASM/Debugger enabled (which use RCM), and the results weren't great. Given we make RCM requests every 5s, smallish changes here should add up, though the real-world effect will be tricky to gauge.

Implementation details

Most of the individual changes are small. In summary:

  • Making work lazy where possible (delaying creating collections)
    • Don't re-create dictionaries inside loops if not required
    • Avoid creating empty dictionaries and collections for no-op RCM responses
    • Avoid creating empty collections in JSON objects when they're not in the JSON
  • Cache things that change rarely
    • The ExtraServicesProvider will rarely see new service names, so cache the array (as the collection is append-only)
    • Don't create a new request each time, just update any values that may have changed
    • Cache the capabilities array which will rarely change
      • There's actually a potential threading bug around the use of BigInteger. We probably could/should use ulong instead but that I'll look at that in a separate PR
  • Use abstractions introduced earlier in the stack (e.g. Add Base64DecodingStream #8226, Add an IArrayPool<char> implementation for vendored Newtonsoft.JSON #8228)

Additionally, I did a little bit of cleanup:

  • Remove unused members from the IRcmSubscriptionManager interface
  • Add #nullable enable to the RCM types (and fix nullability where required)

Test coverage

Mostly covered by existing unit tests, also did some manual testing. Finally, ran a few benchmarks, but it's a bit tricky to check reliably. This benchmark is benchmarking _manager.SendRequest(_rcmTracer, _ => _steadyStateResponseTask) and passing the same response every time. In practice, the response changes every time, so this isn't strictly representative, but with the changes to request caching, this should actually mean our improvements are better than the original would be. The regression in the .NET duration is curious, but I'm not massively concerned, and the allocations are obviously down a lot at least

Method Runtime Mean Error Allocated
PollSteadyState_Original .NET 10.0 14,235.8 ns 275.09 ns 12.04 KB
PollSteadyState_Updated .NET 10.0 20,472.0 ns 1,352.567 ns 3.90 KB
PollSteadyState_Original .NET 6.0 33,915.7 ns 3,339.42 ns 12.27 KB
PollSteadyState_Updated .NET 6.0 14,979.7 ns 447.784 ns 3.99 KB
PollSteadyState_Original .NET Core 2.1 21,488.2 ns 365.39 ns 12.85 KB
PollSteadyState_Updated .NET Core 2.1 17,847.2 ns 693.510 ns 4.04 KB
PollSteadyState_Original .NET Core 3.1 18,925.2 ns 304.16 ns 12.23 KB
PollSteadyState_Updated .NET Core 3.1 15,407.7 ns 313.26 ns 4.01 KB
PollSteadyState_Original .NET Framework 4.8 20,946.8 ns 320.06 ns 14.21 KB
PollSteadyState_Updated .NET Framework 4.8 16,635.2 ns 266.526 ns 4.40 KB

Other details

https://datadoghq.atlassian.net/browse/LANGPLAT-940

All part of the Remote Config perf stack. I think this is probably about the end of it for now

@andrewlock
andrewlock requested review from a team as code owners February 25, 2026 12:34
@andrewlock andrewlock added type:performance Performance, speed, latency, resource usage (CPU, memory) type:cleanup Minor code clean up area:remote-config labels Feb 25, 2026
@dd-trace-dotnet-ci-bot

dd-trace-dotnet-ci-bot Bot commented Feb 25, 2026

Copy link
Copy Markdown

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (8241) 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
duration75.12 ± (75.05 - 75.35) ms77.57 ± (77.70 - 78.25) ms+3.3%✅⬆️
.NET Framework 4.8 - Bailout
duration79.35 ± (79.17 - 79.54) ms82.32 ± (82.30 - 82.76) ms+3.7%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1081.38 ± (1083.35 - 1089.64) ms1112.99 ± (1113.13 - 1119.85) ms+2.9%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms22.83 ± (22.78 - 22.89) ms23.35 ± (23.29 - 23.41) ms+2.3%✅⬆️
process.time_to_main_ms85.55 ± (85.36 - 85.75) ms89.66 ± (89.46 - 89.86) ms+4.8%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.91 ± (10.91 - 10.92) MB10.91 ± (10.91 - 10.91) MB-0.0%
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms22.70 ± (22.65 - 22.75) ms23.33 ± (23.28 - 23.39) ms+2.8%✅⬆️
process.time_to_main_ms87.37 ± (87.16 - 87.58) ms91.56 ± (91.32 - 91.79) ms+4.8%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.95 ± (10.94 - 10.95) MB10.94 ± (10.93 - 10.94) MB-0.1%
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms248.53 ± (244.48 - 252.58) ms233.08 ± (229.74 - 236.42) ms-6.2%
process.time_to_main_ms490.81 ± (490.09 - 491.53) ms510.65 ± (509.88 - 511.42) ms+4.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed47.59 ± (47.57 - 47.61) MB47.57 ± (47.55 - 47.60) MB-0.0%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.1%
.NET 6 - Baseline
process.internal_duration_ms21.70 ± (21.66 - 21.73) ms22.10 ± (22.05 - 22.15) ms+1.9%✅⬆️
process.time_to_main_ms76.02 ± (75.84 - 76.19) ms78.13 ± (77.96 - 78.30) ms+2.8%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.63 ± (10.63 - 10.63) MB10.64 ± (10.63 - 10.64) MB+0.1%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms21.69 ± (21.64 - 21.74) ms22.00 ± (21.95 - 22.05) ms+1.4%✅⬆️
process.time_to_main_ms77.10 ± (76.91 - 77.29) ms79.20 ± (79.00 - 79.40) ms+2.7%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.74 ± (10.73 - 10.74) MB10.75 ± (10.75 - 10.76) MB+0.1%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms252.78 ± (249.04 - 256.52) ms255.62 ± (251.51 - 259.73) ms+1.1%✅⬆️
process.time_to_main_ms476.80 ± (476.18 - 477.42) ms490.09 ± (489.34 - 490.84) ms+2.8%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.31 ± (48.28 - 48.33) MB48.40 ± (48.38 - 48.41) MB+0.2%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.0%
.NET 8 - Baseline
process.internal_duration_ms19.84 ± (19.80 - 19.88) ms20.30 ± (20.26 - 20.35) ms+2.3%✅⬆️
process.time_to_main_ms74.96 ± (74.80 - 75.13) ms77.34 ± (77.16 - 77.52) ms+3.2%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.66 ± (7.66 - 7.67) MB7.68 ± (7.67 - 7.69) MB+0.2%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms19.91 ± (19.85 - 19.96) ms20.50 ± (20.45 - 20.55) ms+3.0%✅⬆️
process.time_to_main_ms76.13 ± (75.94 - 76.33) ms79.10 ± (78.91 - 79.28) ms+3.9%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.74 ± (7.73 - 7.75) MB7.73 ± (7.72 - 7.74) MB-0.1%
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms191.96 ± (191.30 - 192.61) ms196.74 ± (196.01 - 197.46) ms+2.5%✅⬆️
process.time_to_main_ms456.83 ± (456.15 - 457.51) ms470.80 ± (470.08 - 471.52) ms+3.1%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.07 ± (36.03 - 36.11) MB36.31 ± (36.26 - 36.36) MB+0.7%✅⬆️
runtime.dotnet.threads.count27 ± (27 - 27)27 ± (27 - 27)-0.1%

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration193.52 ± (193.07 - 193.89) ms197.29 ± (197.21 - 198.10) ms+2.0%✅⬆️
.NET Framework 4.8 - Bailout
duration197.27 ± (197.06 - 197.53) ms202.81 ± (202.73 - 203.68) ms+2.8%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1156.60 ± (1159.73 - 1169.08) ms1168.87 ± (1173.21 - 1183.11) ms+1.1%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms188.36 ± (187.93 - 188.79) ms191.64 ± (191.15 - 192.13) ms+1.7%✅⬆️
process.time_to_main_ms81.63 ± (81.42 - 81.84) ms83.13 ± (82.91 - 83.34) ms+1.8%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.14 ± (16.11 - 16.17) MB16.05 ± (16.03 - 16.07) MB-0.6%
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)-0.1%
.NET Core 3.1 - Bailout
process.internal_duration_ms188.79 ± (188.35 - 189.23) ms193.44 ± (192.96 - 193.92) ms+2.5%✅⬆️
process.time_to_main_ms83.03 ± (82.81 - 83.25) ms85.16 ± (84.93 - 85.39) ms+2.6%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.18 ± (16.16 - 16.21) MB16.14 ± (16.12 - 16.16) MB-0.3%
runtime.dotnet.threads.count21 ± (21 - 21)21 ± (21 - 21)-0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms438.28 ± (435.37 - 441.20) ms436.71 ± (433.78 - 439.64) ms-0.4%
process.time_to_main_ms476.88 ± (476.32 - 477.45) ms484.15 ± (483.27 - 485.03) ms+1.5%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed57.93 ± (57.81 - 58.04) MB57.96 ± (57.83 - 58.09) MB+0.1%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)-0.0%
.NET 6 - Baseline
process.internal_duration_ms193.40 ± (192.97 - 193.83) ms196.13 ± (195.61 - 196.64) ms+1.4%✅⬆️
process.time_to_main_ms70.93 ± (70.74 - 71.12) ms71.90 ± (71.67 - 72.12) ms+1.4%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.32 ± (16.22 - 16.41) MB16.38 ± (16.34 - 16.41) MB+0.4%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)+1.7%✅⬆️
.NET 6 - Bailout
process.internal_duration_ms194.02 ± (193.53 - 194.51) ms193.69 ± (193.25 - 194.13) ms-0.2%
process.time_to_main_ms72.66 ± (72.46 - 72.86) ms72.24 ± (72.05 - 72.43) ms-0.6%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.44 ± (16.41 - 16.47) MB16.34 ± (16.25 - 16.43) MB-0.6%
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)-1.8%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms450.02 ± (448.03 - 452.01) ms456.93 ± (455.13 - 458.72) ms+1.5%✅⬆️
process.time_to_main_ms453.60 ± (453.08 - 454.12) ms458.64 ± (457.84 - 459.44) ms+1.1%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed58.05 ± (57.96 - 58.15) MB57.78 ± (57.69 - 57.88) MB-0.5%
runtime.dotnet.threads.count29 ± (29 - 30)29 ± (29 - 29)-0.1%
.NET 8 - Baseline
process.internal_duration_ms190.91 ± (190.47 - 191.36) ms193.23 ± (192.74 - 193.72) ms+1.2%✅⬆️
process.time_to_main_ms70.34 ± (70.12 - 70.56) ms71.17 ± (71.00 - 71.33) ms+1.2%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.78 ± (11.75 - 11.81) MB11.74 ± (11.72 - 11.75) MB-0.4%
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)+0.0%✅⬆️
.NET 8 - Bailout
process.internal_duration_ms190.52 ± (190.17 - 190.87) ms192.86 ± (192.37 - 193.36) ms+1.2%✅⬆️
process.time_to_main_ms71.50 ± (71.35 - 71.66) ms72.09 ± (71.91 - 72.27) ms+0.8%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.79 ± (11.76 - 11.82) MB11.75 ± (11.73 - 11.76) MB-0.3%
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)+0.4%✅⬆️
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms366.50 ± (364.88 - 368.13) ms371.48 ± (370.09 - 372.88) ms+1.4%✅⬆️
process.time_to_main_ms435.92 ± (435.08 - 436.76) ms441.75 ± (440.96 - 442.54) ms+1.3%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed47.79 ± (47.75 - 47.83) MB47.80 ± (47.77 - 47.83) MB+0.0%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)-0.7%
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 (8241) - mean (78ms)  : 74, 82
    master - mean (75ms)  : 73, 77

    section Bailout
    This PR (8241) - mean (83ms)  : 79, 86
    master - mean (79ms)  : 77, 81

    section CallTarget+Inlining+NGEN
    This PR (8241) - mean (1,116ms)  : 1069, 1164
    master - mean (1,086ms)  : 1041, 1132

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 (8241) - mean (120ms)  : 116, 125
    master - mean (116ms)  : 113, 119

    section Bailout
    This PR (8241) - mean (122ms)  : 118, 126
    master - mean (117ms)  : 114, 121

    section CallTarget+Inlining+NGEN
    This PR (8241) - mean (785ms)  : 734, 836
    master - mean (776ms)  : 715, 837

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8241) - mean (107ms)  : 103, 111
    master - mean (104ms)  : 100, 108

    section Bailout
    This PR (8241) - mean (108ms)  : 106, 110
    master - mean (106ms)  : 103, 108

    section CallTarget+Inlining+NGEN
    This PR (8241) - mean (783ms)  : 712, 854
    master - mean (765ms)  : 695, 835

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

    section Bailout
    This PR (8241) - mean (108ms)  : 105, 110
    master - mean (104ms)  : 102, 106

    section CallTarget+Inlining+NGEN
    This PR (8241) - mean (707ms)  : 685, 728
    master - mean (681ms)  : 655, 707

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 (8241) - mean (198ms)  : 192, 203
    master - mean (193ms)  : 189, 198

    section Bailout
    This PR (8241) - mean (203ms)  : 197, 210
    master - mean (197ms)  : 195, 199

    section CallTarget+Inlining+NGEN
    This PR (8241) - mean (1,178ms)  : 1103, 1253
    master - mean (1,164ms)  : 1092, 1237

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 (8241) - mean (283ms)  : 273, 293
    master - mean (278ms)  : 273, 284

    section Bailout
    This PR (8241) - mean (287ms)  : 277, 297
    master - mean (280ms)  : 274, 287

    section CallTarget+Inlining+NGEN
    This PR (8241) - mean (955ms)  : 916, 994
    master - mean (948ms)  : 906, 989

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8241) - mean (277ms)  : 269, 284
    master - mean (273ms)  : 267, 279

    section Bailout
    This PR (8241) - mean (274ms)  : 268, 281
    master - mean (275ms)  : 266, 284

    section CallTarget+Inlining+NGEN
    This PR (8241) - mean (946ms)  : 914, 977
    master - mean (936ms)  : 903, 970

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8241) - mean (274ms)  : 265, 284
    master - mean (271ms)  : 264, 277

    section Bailout
    This PR (8241) - mean (275ms)  : 268, 282
    master - mean (272ms)  : 268, 276

    section CallTarget+Inlining+NGEN
    This PR (8241) - mean (846ms)  : 817, 875
    master - mean (835ms)  : 815, 855

Loading

@andrewlock
andrewlock force-pushed the andrew/remote-config/perf branch from 5723a48 to 1f2fe4b Compare February 25, 2026 17:31
@andrewlock
andrewlock force-pushed the andrew/remote-config/root-version branch from 33707ed to c42e395 Compare February 25, 2026 17:31
@pr-commenter

pr-commenter Bot commented Feb 25, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-03-10 15:59:26

Comparing candidate commit 01edb31 in PR branch andrew/remote-config/perf with baseline commit f05ab32 in branch master.

Found 13 performance improvements and 8 performance regressions! Performance is the same for 158 metrics, 13 unstable metrics.

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

  • 🟥 execution_time [+76.914ms; +79.470ms] or [+63.132%; +65.230%]
  • 🟥 throughput [-7546.238op/s; -5956.797op/s] or [-7.520%; -5.936%]

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

  • 🟩 execution_time [-80.401ms; -80.315ms] or [-39.958%; -39.915%]

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

  • 🟩 execution_time [-106.284ms; -106.169ms] or [-49.201%; -49.148%]

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

  • 🟥 execution_time [+10.243ms; +15.705ms] or [+5.123%; +7.855%]

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

  • 🟥 throughput [-85759.648op/s; -81655.285op/s] or [-8.551%; -8.142%]

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

  • 🟩 execution_time [-26.399ms; -20.054ms] or [-12.163%; -9.240%]

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

  • 🟩 execution_time [-22.849ms; -17.024ms] or [-10.527%; -7.844%]

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

  • 🟩 execution_time [-22.475ms; -21.774ms] or [-11.115%; -10.768%]

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

  • 🟩 execution_time [-98.371ms; -93.838ms] or [-48.774%; -46.526%]

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

  • 🟥 execution_time [+68.400µs; +73.067µs] or [+6.605%; +7.056%]
  • 🟥 throughput [-63.747op/s; -59.740op/s] or [-6.601%; -6.186%]

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

  • 🟩 execution_time [-181.279µs; -134.441µs] or [-8.331%; -6.178%]
  • 🟩 throughput [+31.137op/s; +40.402op/s] or [+6.773%; +8.788%]

scenario:Benchmarks.Trace.DbCommandBenchmark.ExecuteNonQuery netcoreapp3.1

  • 🟩 throughput [+35198.199op/s; +43280.684op/s] or [+9.579%; +11.779%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch net472

  • 🟩 throughput [+16916.215op/s; +18310.039op/s] or [+5.590%; +6.050%]

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

  • 🟩 throughput [+33382.996op/s; +47534.992op/s] or [+6.641%; +9.457%]

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

  • 🟩 throughput [+2561.489op/s; +4226.481op/s] or [+14.424%; +23.800%]

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

  • 🟥 throughput [-20283879.754op/s; -19431359.518op/s] or [-8.293%; -7.944%]

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

  • 🟥 execution_time [+18.841ms; +24.259ms] or [+9.562%; +12.312%]

scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net472

  • 🟩 throughput [+38195.855op/s; +43296.032op/s] or [+5.701%; +6.462%]

@andrewlock
andrewlock force-pushed the andrew/remote-config/root-version branch from c42e395 to bc2260d Compare March 10, 2026 09:58
@andrewlock
andrewlock requested review from a team as code owners March 10, 2026 09:58
@andrewlock
andrewlock requested review from anna-git and duncanpharvey and removed request for a team March 10, 2026 09:58
Base automatically changed from andrew/remote-config/root-version to master March 10, 2026 15:14
@andrewlock
andrewlock force-pushed the andrew/remote-config/perf branch from bcb7f2b to 01edb31 Compare March 10, 2026 15:16

@bouwkast bouwkast left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

😅

There is a lot here I think it looks good though from what I can see

I thought that we can't swap to ulong compared to BigInteger thought that was an issue a while back? Maybe misremembering


var remoteConfigurationCache = new RemoteConfigurationCache(remoteConfigurationPath, signedTarget.Length, signedTarget.Hashes, signedTarget.Custom.V);
_appliedConfigurations[remoteConfigurationCache.Path.Path] = remoteConfigurationCache;
var targetFile = response.TargetFiles?.FirstOrDefault(file => file.Path == remoteConfigurationPath.Path);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How long would TargetFiles be usually? It used to be a TryGetValue so wondering if this is where the increased time came?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I tested this locally, by enabling ASM and debugging using

dd-trace run --set-env DD_TRACE_DEBUG=1 --set-env DD_LOGS_DIRECT_SUBMISSION_INTEGRATIONS=Serilog --set-env DD_APPSEC_ENABLED=1 --set-env DD_DYNAMIC_INSTRUMENTATION_ENABLED=1 --tracer-home C:\repos\dd-trace-dotnet-2\shared\bin\monitoring-home -- "C:\repos\test\logging_sample\bin\Debug\net5.0\publish\logging_sample.exe"

and the maximum size of target_files was "3" 😅 I expect it would likely get bigger than that if there's more being pushed via remote config, but I would be surprised to see more than 8, so I doubt this will be the source...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It doesn't explain the benchmark regression though, because that was only 2/3 target files 😅

@andrewlock

Copy link
Copy Markdown
Member Author

Just for some extra context, I did manual testing to look into this, and also some crude benchmarks

#nullable enable

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using Datadog.Trace.RemoteConfigurationManagement;
using Datadog.Trace.RemoteConfigurationManagement.Protocol;
using Datadog.Trace.RemoteConfigurationManagement.Protocol.Tuf;
using Datadog.Trace.Util;
using Datadog.Trace.Util.Json;
using Datadog.Trace.Util.Streams;
using Datadog.Trace.Vendors.Newtonsoft.Json;

namespace Benchmarks.Trace
{
    /// <summary>
    /// Benchmarks for the Remote Configuration Management polling pipeline.
    /// Covers: request building, response processing (steady-state), and response deserialization.
    /// </summary>
    [MemoryDiagnoser, GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory), CategoriesColumn]
    public class RemoteConfigBenchmark
    {
        private static readonly Task<GetRcmResponse?> NullResponseTask = Task.FromResult<GetRcmResponse?>(null);

        private RcmSubscriptionManager _manager = null!;
        private RcmClientTracer _rcmTracer = null!;
        private Task<GetRcmResponse?> _steadyStateResponseTask = null!;
        private byte[] _serializedResponseBytes = null!;
        private byte[] _hugeSerializedResponseBytes = null!;
        private GetRcmResponse? _response;
        private string _pathToTest;
        private string _result;

        [GlobalSetup]
        public void GlobalSetup()
        {
            _rcmTracer = RcmClientTracer.Create(
                runtimeId: "benchmark-runtime-id",
                tracerVersion: "2.55.0",
                service: "benchmark-service",
                env: "benchmark",
                appVersion: "1.0.0",
                globalTags: new ReadOnlyDictionary<string, string>(new Dictionary<string, string>
                {
                    { "team", "apm" },
                    { "component", "benchmark" }
                }),
                processTags: null);

            _manager = new RcmSubscriptionManager();

            // Subscribe with a realistic subscription covering multiple products
            var subscription = new Subscription(
                (configs, removed) =>
                {
                    var results = new List<ApplyDetails>();
                    foreach (var product in configs)
                    {
                        foreach (var config in product.Value)
                        {
                            results.Add(ApplyDetails.FromOk(config.Path.Path));
                        }
                    }

                    return results.ToArray();
                },
                RcmProducts.AsmFeatures,
                RcmProducts.AsmDd);
            _manager.SubscribeToChanges(subscription);

            // Set capabilities as real code would
            _manager.SetCapability(RcmCapabilitiesIndices.AsmActivation, true);
            _manager.SetCapability(RcmCapabilitiesIndices.AsmIpBlocking, true);
            _manager.SetCapability(RcmCapabilitiesIndices.AsmDdRules, true);
            _manager.SetCapability(RcmCapabilitiesIndices.AsmExclusion, true);
            _manager.SetCapability(RcmCapabilitiesIndices.ApmTracingSampleRate, true);

            // Create initial response and prime the manager (applies all configs)
            var initialResponse = CreateResponse(configCount: 5);
            _manager.SendRequest(_rcmTracer, _ => Task.FromResult<GetRcmResponse?>(initialResponse))
                .GetAwaiter().GetResult();

            // Steady-state response: identical configs/hashes so ProcessResponse detects no changes
            _steadyStateResponseTask = Task.FromResult<GetRcmResponse?>(CreateResponse(configCount: 5));

            // Serialize for deserialization benchmark (includes base64-encoded TufRoot)
            _serializedResponseBytes = Encoding.UTF8.GetBytes(
                """
                {
                	"targets": "eyJzaWduZWQiOnsiX3R5cGUiOiJ0YXJnZXRzIiwiY3VzdG9tIjp7Im9wYXF1ZV9iYWNrZW5kX3N0YXRlIjoiZXlKbWIyOGlPaUFpWW1GeUluMD0ifSwiZXhwaXJlcyI6IjMwMDAtMDEtMDFUMDA6MDA6MDBaIiwic3BlY192ZXJzaW9uIjoiMS4wIiwidGFyZ2V0cyI6eyJkYXRhZG9nLzIvQVNNX0ZFQVRVUkVTL0FTTV9GRUFUVVJFUy1iYXNlL2NvbmZpZyI6eyJjdXN0b20iOnsidiI6Mn0sImhhc2hlcyI6eyJzaGEyNTYiOiJhMzhlYmY5ZmEyNTYwNzFmOTgyM2E1ZjUxMmE4NGU4YTc4NmM4ZGEyYjA3MTk0NTJkZWViNWRjMjg3ZWM5OTBmIn0sImxlbmd0aCI6NDh9LCJkYXRhZG9nLzIvQVNNX0ZFQVRVUkVTL0FTTV9GRUFUVVJFUy1zZWNvbmQvY29uZmlnIjp7ImN1c3RvbSI6eyJ2IjoxfSwiaGFzaGVzIjp7InNoYTI1NiI6IjkyMjFkZmQ5ZjYwODQxNTEzMTNlM2U0OTIwMTIxYWU4NDM2MTRjMzI4ZTQ2MzBlYTM3MWJhNjZlMmYxNWEwYTYifSwibGVuZ3RoIjo0N30sImRhdGFkb2cvMi9BU01fRkVBVFVSRVMvQVNNX0ZFQVRVUkVTLXRoaXJkL3Rlc3RuYW1lIjp7ImN1c3RvbSI6eyJ2IjoxfSwiaGFzaGVzIjp7InNoYTI1NiI6IjFlNGE3NWVkZmQ1ZjY1ZTBhZGVjNzA0Y2M3YzMyZjc5OTg3MTE3ZDg0NzU1NTQ0YWU0OTA1MDQ1Y2RiMGE0NDMifSwibGVuZ3RoIjo0MX0sImRhdGFkb2cvMi9ST0dVRV9QUk9EVUNUL215Y29uZmlnL2NvbmZpZyI6eyJjdXN0b20iOnsidiI6MX0sImhhc2hlcyI6eyJzaGEyNTYiOiI0NTliZDZhNDAzZDhkNTA5YzQ0M2Q3YjQ2NTVkMDI3YWRhM2NhZGUzM2U4YTM5ZjBkNTQ3ZDAyZjRkYjJkM2Q1In0sImxlbmd0aCI6OH0sImRhdGFkb2cvMi9ST0dVRV9QUk9EVUNUL215Y29uZmlnMi9jb25maWciOnsiY3VzdG9tIjp7InYiOjF9LCJoYXNoZXMiOnsic2hhMjU2IjoiYWZlZjkzNDJlNTZmNDQ2NTJhM2E5YWNkZjRiZGZlZGZlOGRhYjJlMDQ5Nzg4NzM0MTRmNjQzOTU0NDRmZjU0MSJ9LCJsZW5ndGgiOjEyfX0sInZlcnNpb24iOjEyfSwic2lnbmF0dXJlcyI6W3sia2V5aWQiOiJlZDc2NzJjOWEyNGFiZGE3ODg3MmVlMzJlZTcxYzdjYjFkNTIzNWU4ZGI0ZWNiZjFjYTI4YjljNTBlYjc1ZDllIiwic2lnIjoiNWY0YzQxOGQ1NWRhMGQ0ODU5YWIwNzM2MzUzODQ0NDAwMDczMjI1MTI3YjQxNzZmM2FhOGI1ZjViMWFkMDQxNGU4MTZiZWMyYWFiMGRmYTcyMzg0N2FmZDkzZmMxMTEzMmZiYjliMDY0Mzk0YWMwODYwZGNjZDcxZTgxNDc4MGYifV19",
                	"target_files": [
                		{
                			"path": "datadog/2/ASM_FEATURES/ASM_FEATURES-third/testname",
                			"raw": "ewogICJhc20iOiB7CiAgICAgICJlbmFibGVkIjogdHJ1ZQogIH0KfQo="
                		}
                	],
                	"client_configs": [
                		"datadog/2/ASM_FEATURES/ASM_FEATURES-base/config",
                		"datadog/2/ASM_FEATURES/ASM_FEATURES-second/config",
                		"datadog/2/ASM_FEATURES/ASM_FEATURES-third/testname"
                	]
                }
                """);

            _hugeSerializedResponseBytes = Encoding.UTF8.GetBytes(RemoteConfigData.HugeConfig());
            _pathToTest = "datadog/2/ASM_FEATURES/ASM_FEATURES-third/testname";
        }

        /// <summary>
        /// Full poll cycle when nothing has changed (the most common real-world scenario).
        /// Exercises BuildRequest + ProcessResponse: hash comparison, path parsing,
        /// ToDictionary creation, List.Contains lookups, LINQ in Update().
        /// </summary>
        [Benchmark]
        public Task PollSteadyState()
        {
            return _manager.SendRequest(_rcmTracer, _ => _steadyStateResponseTask);
        }

        /// <summary>
        /// Full poll cycle when nothing has changed (the most common real-world scenario).
        /// Exercises BuildRequest + ProcessResponse: hash comparison, path parsing,
        /// ToDictionary creation, List.Contains lookups, LINQ in Update().
        /// </summary>
        [Benchmark]
        public Task PollChanging()
        {
            return _manager.SendRequest(_rcmTracer, _ => _steadyStateResponseTask);
        }

        /// <summary>
        /// Request building only (callback returns null so ProcessResponse is skipped).
        /// Exercises: LINQ Select/ToList for hashes, RcmCachedTargetFile/RcmConfigState
        /// allocation, GetCapabilities byte[] creation.
        /// </summary>
        [Benchmark]
        public Task BuildRequest()
        {
            return _manager.SendRequest(_rcmTracer, _ => NullResponseTask);
        }
    }
}

@andrewlock
andrewlock merged commit 489fc21 into master Mar 11, 2026
139 checks passed
@andrewlock
andrewlock deleted the andrew/remote-config/perf branch March 11, 2026 15:56
@github-actions github-actions Bot added this to the vNext-v3 milestone Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:remote-config type:cleanup Minor code clean up type:performance Performance, speed, latency, resource usage (CPU, memory)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants