Skip to content

[Test Optimization] perf: logging/timing helpers#8070

Merged
tonyredondo merged 7 commits intomasterfrom
tony/testoptimization-performance-work-pr1
Jan 30, 2026
Merged

[Test Optimization] perf: logging/timing helpers#8070
tonyredondo merged 7 commits intomasterfrom
tony/testoptimization-performance-work-pr1

Conversation

@tonyredondo
Copy link
Member

@tonyredondo tonyredondo commented Jan 15, 2026

Summary of changes

  • Add FixedSizeArrayPool and logger overloads to reduce per-log allocations.
  • Add RefStopwatch/StopwatchHelpers/CodeDuration and apply timing to TraceClock/TracerManagerFactory/Instrumentation and CI processors.
  • Lower init logs to Debug for CI protocol writer/sender and processors.

Reason for change

Reduce allocations and improve timing diagnostics in hot paths.

Implementation details

  • New utility helpers in Datadog.Trace.Util for allocation-free timing and pooling.
  • Logging changes to avoid params array allocations in common log paths.
  • Timing/log-level tweaks in CI protocol writer/sender and trace processors.

Test coverage

CI passes then all changes are good.

Other details

@tonyredondo tonyredondo changed the title perf: logging/timing helpers [Test Optimization] perf: logging/timing helpers Jan 15, 2026
@pr-commenter
Copy link

pr-commenter bot commented Jan 15, 2026

Benchmarks

Benchmark execution time: 2026-01-30 12:13:33

Comparing candidate commit 90b2923 in PR branch tony/testoptimization-performance-work-pr1 with baseline commit 3d020db in branch master.

Found 3 performance improvements and 14 performance regressions! Performance is the same for 160 metrics, 15 unstable metrics.

scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net472

  • 🟥 throughput [-6314.778op/s; -5796.540op/s] or [-7.085%; -6.504%]

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

  • 🟩 throughput [+4752.715op/s; +6232.273op/s] or [+5.178%; +6.790%]

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

  • 🟥 execution_time [+108.169ms; +108.888ms] or [+98.219%; +98.871%]

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

  • 🟥 execution_time [+27.082ms; +27.195ms] or [+15.275%; +15.338%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟩 execution_time [-20.612ms; -14.769ms] or [-9.567%; -6.855%]

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

  • 🟥 execution_time [+101.419µs; +107.474µs] or [+7.135%; +7.560%]
  • 🟥 throughput [-49.477op/s; -46.811op/s] or [-7.033%; -6.654%]

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

  • 🟥 throughput [-38376.427op/s; -31108.806op/s] or [-8.951%; -7.256%]

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

  • 🟥 execution_time [+12.758ms; +17.320ms] or [+6.472%; +8.786%]

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

  • 🟥 throughput [-511.737op/s; -309.780op/s] or [-23.043%; -13.949%]

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

  • 🟥 throughput [-53024.493op/s; -40037.771op/s] or [-9.904%; -7.479%]

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

  • 🟥 execution_time [+18.494ms; +19.309ms] or [+20.255%; +21.147%]

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

  • 🟥 execution_time [+12.735ms; +16.204ms] or [+6.390%; +8.131%]
  • 🟥 throughput [-97292.614op/s; -79890.252op/s] or [-8.818%; -7.241%]

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

  • 🟥 execution_time [+16.183ms; +21.281ms] or [+8.102%; +10.655%]

scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net472

  • 🟥 throughput [-92234.851op/s; -89630.979op/s] or [-12.805%; -12.443%]

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

  • 🟩 execution_time [-21.575ms; -17.679ms] or [-9.973%; -8.172%]

@tonyredondo tonyredondo force-pushed the tony/testoptimization-performance-work-pr1 branch from ad6c32d to f0ccdd2 Compare January 15, 2026 22:06
@dd-trace-dotnet-ci-bot
Copy link

dd-trace-dotnet-ci-bot bot commented Jan 15, 2026

Execution-Time Benchmarks Report ⏱️

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

⚠️ Potential regressions detected

FakeDbCommand

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Bailout
duration72.43 ± (72.33 - 72.57) ms77.76 ± (77.54 - 77.92) ms+7.4%❌⬆️
Full Metrics Comparison

FakeDbCommand

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration68.49 ± (68.52 - 68.84) ms73.16 ± (73.21 - 73.56) ms+6.8%✅⬆️
.NET Framework 4.8 - Bailout
duration72.43 ± (72.33 - 72.57) ms77.76 ± (77.54 - 77.92) ms+7.4%❌⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1023.25 ± (1029.36 - 1039.28) ms1053.82 ± (1055.12 - 1062.71) ms+3.0%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms21.86 ± (21.83 - 21.88) ms22.71 ± (22.66 - 22.75) ms+3.9%✅⬆️
process.time_to_main_ms78.76 ± (78.61 - 78.92) ms86.37 ± (86.17 - 86.57) ms+9.7%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.90 ± (10.90 - 10.91) MB10.92 ± (10.91 - 10.92) MB+0.1%✅⬆️
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms21.75 ± (21.73 - 21.77) ms22.59 ± (22.54 - 22.63) ms+3.8%✅⬆️
process.time_to_main_ms80.02 ± (79.91 - 80.12) ms87.34 ± (87.16 - 87.52) ms+9.2%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.94 ± (10.94 - 10.94) MB10.95 ± (10.95 - 10.96) MB+0.1%✅⬆️
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms241.72 ± (238.00 - 245.43) ms238.84 ± (234.92 - 242.77) ms-1.2%
process.time_to_main_ms474.07 ± (473.38 - 474.76) ms505.28 ± (504.39 - 506.18) ms+6.6%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.56 ± (48.54 - 48.59) MB48.58 ± (48.56 - 48.60) MB+0.0%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.8%
.NET 6 - Baseline
process.internal_duration_ms20.65 ± (20.62 - 20.69) ms21.56 ± (21.52 - 21.60) ms+4.4%✅⬆️
process.time_to_main_ms68.36 ± (68.23 - 68.49) ms74.83 ± (74.65 - 75.00) ms+9.5%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.62 ± (10.61 - 10.62) MB10.64 ± (10.64 - 10.64) MB+0.2%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms20.52 ± (20.49 - 20.54) ms21.44 ± (21.39 - 21.49) ms+4.5%✅⬆️
process.time_to_main_ms69.27 ± (69.21 - 69.33) ms75.20 ± (75.02 - 75.38) ms+8.6%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.67 ± (10.67 - 10.67) MB10.75 ± (10.75 - 10.76) MB+0.8%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms250.13 ± (249.04 - 251.22) ms238.31 ± (234.35 - 242.26) ms-4.7%
process.time_to_main_ms451.92 ± (451.43 - 452.42) ms478.00 ± (477.30 - 478.70) ms+5.8%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed49.29 ± (49.26 - 49.32) MB49.30 ± (49.27 - 49.32) MB+0.0%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.1%
.NET 8 - Baseline
process.internal_duration_ms18.70 ± (18.67 - 18.72) ms19.66 ± (19.62 - 19.69) ms+5.1%✅⬆️
process.time_to_main_ms67.05 ± (66.95 - 67.16) ms73.73 ± (73.56 - 73.90) ms+10.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.69 ± (7.68 - 7.69) MB7.69 ± (7.68 - 7.70) MB+0.0%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms18.74 ± (18.71 - 18.76) ms19.72 ± (19.68 - 19.77) ms+5.3%✅⬆️
process.time_to_main_ms68.32 ± (68.25 - 68.38) ms75.39 ± (75.22 - 75.57) ms+10.4%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.73 ± (7.72 - 7.74) MB7.73 ± (7.73 - 7.74) MB+0.1%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms178.01 ± (177.28 - 178.75) ms187.74 ± (187.01 - 188.47) ms+5.5%✅⬆️
process.time_to_main_ms435.35 ± (434.71 - 436.00) ms459.31 ± (458.52 - 460.09) ms+5.5%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.69 ± (36.66 - 36.72) MB36.78 ± (36.75 - 36.81) MB+0.3%✅⬆️
runtime.dotnet.threads.count27 ± (27 - 27)27 ± (27 - 27)-0.4%

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration193.95 ± (194.21 - 195.30) ms194.04 ± (193.91 - 194.73) ms+0.0%✅⬆️
.NET Framework 4.8 - Bailout
duration197.41 ± (197.38 - 197.93) ms198.06 ± (198.03 - 198.81) ms+0.3%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1137.50 ± (1138.97 - 1147.41) ms1149.20 ± (1154.47 - 1164.46) ms+1.0%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms188.25 ± (187.91 - 188.59) ms188.52 ± (188.15 - 188.89) ms+0.1%✅⬆️
process.time_to_main_ms81.73 ± (81.44 - 82.02) ms81.91 ± (81.69 - 82.13) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.15 ± (16.12 - 16.18) MB16.09 ± (16.07 - 16.11) MB-0.4%
runtime.dotnet.threads.count20 ± (19 - 20)20 ± (19 - 20)+0.1%✅⬆️
.NET Core 3.1 - Bailout
process.internal_duration_ms187.65 ± (187.35 - 187.95) ms187.64 ± (187.36 - 187.93) ms-0.0%
process.time_to_main_ms82.80 ± (82.66 - 82.94) ms83.08 ± (82.94 - 83.23) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.20 ± (16.17 - 16.23) MB16.13 ± (16.11 - 16.16) MB-0.4%
runtime.dotnet.threads.count21 ± (20 - 21)21 ± (20 - 21)+0.1%✅⬆️
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms431.37 ± (428.25 - 434.49) ms435.02 ± (432.69 - 437.35) ms+0.8%✅⬆️
process.time_to_main_ms480.75 ± (480.06 - 481.43) ms483.38 ± (482.65 - 484.12) ms+0.5%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed58.93 ± (58.82 - 59.05) MB59.01 ± (58.91 - 59.11) MB+0.1%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)+0.0%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms192.54 ± (192.22 - 192.86) ms193.50 ± (193.07 - 193.93) ms+0.5%✅⬆️
process.time_to_main_ms70.78 ± (70.58 - 70.97) ms71.14 ± (70.88 - 71.39) ms+0.5%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.34 ± (16.31 - 16.37) MB16.33 ± (16.27 - 16.40) MB-0.0%
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)+0.3%✅⬆️
.NET 6 - Bailout
process.internal_duration_ms191.96 ± (191.62 - 192.31) ms192.38 ± (192.00 - 192.75) ms+0.2%✅⬆️
process.time_to_main_ms71.94 ± (71.80 - 72.09) ms72.24 ± (72.09 - 72.39) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.28 ± (16.16 - 16.40) MB16.34 ± (16.24 - 16.43) MB+0.4%✅⬆️
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)+0.5%✅⬆️
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms441.98 ± (438.85 - 445.10) ms450.82 ± (448.32 - 453.31) ms+2.0%✅⬆️
process.time_to_main_ms458.69 ± (458.22 - 459.15) ms460.18 ± (459.66 - 460.71) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed59.06 ± (58.93 - 59.19) MB59.06 ± (58.95 - 59.18) MB+0.0%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)+0.0%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms190.42 ± (190.04 - 190.81) ms191.16 ± (190.76 - 191.55) ms+0.4%✅⬆️
process.time_to_main_ms70.12 ± (69.92 - 70.31) ms70.47 ± (70.27 - 70.67) ms+0.5%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.75 ± (11.72 - 11.78) MB11.75 ± (11.73 - 11.78) MB+0.0%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)-0.0%
.NET 8 - Bailout
process.internal_duration_ms189.30 ± (189.05 - 189.56) ms190.62 ± (190.26 - 190.97) ms+0.7%✅⬆️
process.time_to_main_ms70.96 ± (70.86 - 71.06) ms71.69 ± (71.52 - 71.85) ms+1.0%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.82 ± (11.79 - 11.85) MB11.79 ± (11.76 - 11.82) MB-0.2%
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)+0.5%✅⬆️
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms367.13 ± (365.75 - 368.50) ms366.63 ± (365.10 - 368.16) ms-0.1%
process.time_to_main_ms442.90 ± (441.99 - 443.81) ms447.10 ± (446.28 - 447.91) ms+0.9%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed48.37 ± (48.33 - 48.40) MB48.32 ± (48.29 - 48.36) MB-0.1%
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)+0.6%✅⬆️
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 (8070) - mean (73ms)  : 71, 76
    master - mean (69ms)  : 67, 71

    section Bailout
    This PR (8070) - mean (78ms)  : crit, 76, 80
    master - mean (72ms)  : 71, 74

    section CallTarget+Inlining+NGEN
    This PR (8070) - mean (1,059ms)  : 1004, 1113
    master - mean (1,034ms)  : 962, 1106

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 (8070) - mean (116ms)  : 113, 120
    master - mean (106ms)  : 104, 108

    section Bailout
    This PR (8070) - mean (117ms)  : crit, 115, 119
    master - mean (107ms)  : 106, 108

    section CallTarget+Inlining+NGEN
    This PR (8070) - mean (784ms)  : 726, 841
    master - mean (741ms)  : 683, 799

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8070) - mean (103ms)  : 99, 106
    master - mean (94ms)  : 91, 96

    section Bailout
    This PR (8070) - mean (103ms)  : crit, 101, 106
    master - mean (94ms)  : 93, 95

    section CallTarget+Inlining+NGEN
    This PR (8070) - mean (747ms)  : 666, 828
    master - mean (728ms)  : 703, 753

Loading
FakeDbCommand (.NET 8)
gantt
    title Execution time (ms) FakeDbCommand (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8070) - mean (101ms)  : 98, 104
    master - mean (92ms)  : 89, 95

    section Bailout
    This PR (8070) - mean (103ms)  : crit, 100, 106
    master - mean (93ms)  : 92, 94

    section CallTarget+Inlining+NGEN
    This PR (8070) - mean (686ms)  : crit, 662, 710
    master - mean (644ms)  : 628, 660

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 (8070) - mean (194ms)  : 190, 199
    master - mean (195ms)  : 189, 201

    section Bailout
    This PR (8070) - mean (198ms)  : 195, 202
    master - mean (198ms)  : 195, 200

    section CallTarget+Inlining+NGEN
    This PR (8070) - mean (1,159ms)  : 1083, 1236
    master - mean (1,143ms)  : 1082, 1204

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 (8070) - mean (279ms)  : 273, 284
    master - mean (278ms)  : 272, 284

    section Bailout
    This PR (8070) - mean (279ms)  : 276, 283
    master - mean (279ms)  : 275, 282

    section CallTarget+Inlining+NGEN
    This PR (8070) - mean (945ms)  : 893, 998
    master - mean (942ms)  : 894, 990

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8070) - mean (273ms)  : 266, 280
    master - mean (272ms)  : 266, 278

    section Bailout
    This PR (8070) - mean (273ms)  : 268, 277
    master - mean (272ms)  : 267, 277

    section CallTarget+Inlining+NGEN
    This PR (8070) - mean (940ms)  : 904, 976
    master - mean (928ms)  : 874, 982

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8070) - mean (272ms)  : 267, 277
    master - mean (270ms)  : 264, 276

    section Bailout
    This PR (8070) - mean (272ms)  : 268, 276
    master - mean (270ms)  : 267, 273

    section CallTarget+Inlining+NGEN
    This PR (8070) - mean (844ms)  : 826, 863
    master - mean (841ms)  : 825, 857

Loading

@datadog-datadog-prod-us1

This comment has been minimized.

{
// Tells us which types are loaded, when, and how often.
SharedLogger.Debug("Logger retrieved for: {AssemblyQualifiedName}", classType.AssemblyQualifiedName);
if (SharedLogger.IsEnabled(LogEventLevel.Debug))
Copy link
Member Author

Choose a reason for hiding this comment

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

RuntimeType.AssemblyQualifiedName always allocates a new string and do some internals QCalls, is fast but we can avoid it.

Comment on lines +219 to +220
using var array = FixedSizeArrayPool<object?>.OneItemPool.Get();
array.Array[0] = property;
Copy link
Member Author

Choose a reason for hiding this comment

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

previously we allocate an array for every single log line, here the idea is to have a small pool for it and reuse it.

{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _utcStart.Add(Elapsed);
get => _utcStart.AddTicks(StopwatchHelpers.GetElapsedTicks(Stopwatch.GetTimestamp() - _timestamp));
Copy link
Member Author

Choose a reason for hiding this comment

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

we really don't need to create a TimeSpan struct for this by calling Elapsed, we just count the ticks and add them.

Copy link
Member

Choose a reason for hiding this comment

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

is this measurably faster?

Copy link
Member Author

Choose a reason for hiding this comment

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

not in recent frameworks, in olders frameworks the codegen is just a little better.


namespace Datadog.Trace.Util;

internal struct CodeDuration : IDisposable
Copy link
Member Author

@tonyredondo tonyredondo Jan 16, 2026

Choose a reason for hiding this comment

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

This is the version for use in an async/await method because we cannot use ref struct there. So creating a CodeDuration in that case will allocate in the heap (struct boxing).

Below there's the ref struct version to avoid any heap allocation in a normal sync method.

Copy link
Contributor

@dudikeleti dudikeleti Jan 20, 2026

Choose a reason for hiding this comment

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

Would it make sense to add a short comment in code about when to use CodeDuration vs CodeDurationRef?
My concern is that if someone uses the struct version in a non async methos and in a non-local way (copied by value) he could end up calling Dispose() on multiple copies and get an incorrect CodeDurationBase.Count.

Copy link
Member Author

Choose a reason for hiding this comment

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

done in 5cb68e6

}
}

internal ref struct CodeDurationRef
Copy link
Member Author

Choose a reason for hiding this comment

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

ref struct version to avoid an allocation in the heap.

Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: wondering if the code inside the methods / ctors could have been shared between the two via some static helpers , for maintenance

#endif

#if NETCOREAPP3_0_OR_GREATER
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
Copy link
Member Author

Choose a reason for hiding this comment

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

we clear the array if we know that T is a reference type (so we don't hold any reference from the GC)

@tonyredondo tonyredondo force-pushed the tony/testoptimization-performance-work-pr1 branch from 7a2fadb to c58aa40 Compare January 16, 2026 12:39
@tonyredondo tonyredondo marked this pull request as ready for review January 16, 2026 12:40
@tonyredondo tonyredondo requested review from a team as code owners January 16, 2026 12:40
Copy link
Contributor

@dudikeleti dudikeleti left a comment

Choose a reason for hiding this comment

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

Great work


namespace Datadog.Trace.Util;

internal struct CodeDuration : IDisposable
Copy link
Contributor

@dudikeleti dudikeleti Jan 20, 2026

Choose a reason for hiding this comment

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

Would it make sense to add a short comment in code about when to use CodeDuration vs CodeDurationRef?
My concern is that if someone uses the struct version in a non async methos and in a non-local way (copied by value) he could end up calling Dispose() on multiple copies and get an incorrect CodeDurationBase.Count.

@tonyredondo tonyredondo force-pushed the tony/testoptimization-performance-work-pr1 branch from 4a649b1 to 3f3f143 Compare January 23, 2026 13:55
}
}

internal ref struct CodeDurationRef
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: wondering if the code inside the methods / ctors could have been shared between the two via some static helpers , for maintenance

@tonyredondo tonyredondo merged commit 30a543a into master Jan 30, 2026
145 checks passed
@tonyredondo tonyredondo deleted the tony/testoptimization-performance-work-pr1 branch January 30, 2026 15:33
@github-actions github-actions bot added this to the vNext-v3 milestone Jan 30, 2026
tonyredondo added a commit that referenced this pull request Feb 3, 2026
## Summary of changes
- Introduce Test Optimization RunId and EnsureRunId with cache folder
lifecycle.
- Add `_DD_INTERNAL_TOPT_RUNID` to config mapping/docs and regenerate
keys.
- Update CI integration tests to set/print RunId for deterministic runs.
- Adjust test helper thread naming for clearer CI debugging.

## Reason for change
Provide a stable RunId before caching work that depends on it and keep
configuration in sync.

## Implementation details
- Add RunId/EnsureRunId to `ITestOptimization`/`TestOptimization` with
environment propagation.
- Update configuration mapping and generated CI visibility keys.
- Update CI integration tests for RunId coverage.

## Test coverage
CI passes then all changes are good.

## Other details
- Stacked PRs (current marked):
  - PR1 #8070
- **CURRENT**: PR2 #8071
  - PR3 #8072
  - PR4 #8073
tonyredondo added a commit that referenced this pull request Feb 3, 2026
## Summary of changes
- Add git command caching and telemetry improvements for CI visibility.
- Update GitInfo discovery and CI environment logging.
- Update impacted tests for new git discovery behavior.

JIRA: SDTEST-3226

## Reason for change
Reduce git command overhead and improve visibility into CI git metadata
collection.

## Implementation details
- Disk cache keyed by RunId in GitCommandHelper with safe.directory
handling.
- JSON annotations in ProcessHelpers for cache serialization.
- Adjusted CI runner git discovery logic and tests.

## Test coverage
CI passes then all changes are good.

## Other details
- Stacked PRs (current marked):
  - PR1 #8070
  - PR2 #8071
- **CURRENT**: PR3 #8072
  - PR4 #8073
tonyredondo added a commit that referenced this pull request Feb 3, 2026
## Summary of changes
- Add cached/file Test Optimization clients and update client wrappers.
- Reduce feature init overhead and adjust background initialization.
- Improve runner logging and CI workspace cache usage.

## Reason for change
Reduce repeated HTTP calls and improve initialization performance for CI
visibility features.

## Implementation details
- New cached/file client implementations for disk/memory caching.
- Feature creation updated to reduce dependencies on client calls.
- CodeDuration instrumentation added to CI initialization paths.

## Test coverage
CI passes then all changes are good.

## Other details
- Stacked PRs (current marked):
  - PR1 #8070
  - PR2 #8071
  - PR3 #8072
- **CURRENT**: PR4 #8073
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.

6 participants