Skip to content

Conversation

@dudikeleti
Copy link
Contributor

@dudikeleti dudikeleti commented Dec 20, 2025

Reason for change

Some methods can legitimately produce null managed byrefs (e.g., MemoryMarshal.GetReference(emptySpan)), which makes ref T point to address 0. Attempting to capture such locals/args would dereference an invalid reference and could crash in LogLocal/LogArg (NullReferenceException). This change makes DI runs stable and keeps probes installed while avoiding unsafe dereferences

Implementation details

Before reading a ref T capture input, we check Unsafe.IsNullRef(ref value) and return early to avoid dereferencing an invalid reference.

Current behavior is to skip capturing that member entirely (no misleading null value for non-nullable types like byte).
Follow-up option: if we decide we want the snapshot to explicitly show this case, we can reuse the existing snapshot notCapturedReason mechanism (no new reason added in this PR).

Test coverage

#7987

Other details

This PR is part of an effort to make the Snapshot Exploration Test run successfully end-to-end.
#7988
#7989

…ing Unsafe.IsNullRef(ref T) and skip capture instead of dereferencing.
@dd-trace-dotnet-ci-bot
Copy link

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (7986) 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
duration68.37 ± (68.44 - 68.67) ms68.40 ± (68.45 - 68.68) ms+0.0%✅⬆️
.NET Framework 4.8 - Bailout
duration72.04 ± (71.98 - 72.19) ms72.18 ± (72.02 - 72.27) ms+0.2%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1002.12 ± (1004.91 - 1011.87) ms1001.41 ± (1005.11 - 1012.06) ms-0.1%
.NET Core 3.1 - Baseline
process.internal_duration_ms21.95 ± (21.93 - 21.97) ms21.93 ± (21.90 - 21.96) ms-0.1%
process.time_to_main_ms78.46 ± (78.35 - 78.58) ms78.71 ± (78.57 - 78.85) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.90 ± (10.90 - 10.91) MB10.90 ± (10.90 - 10.91) MB+0.0%✅⬆️
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms21.95 ± (21.93 - 21.97) ms21.84 ± (21.82 - 21.86) ms-0.5%
process.time_to_main_ms79.96 ± (79.89 - 80.04) ms79.79 ± (79.67 - 79.90) ms-0.2%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.94 ± (10.93 - 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_ms210.44 ± (209.06 - 211.82) ms212.29 ± (210.83 - 213.76) ms+0.9%✅⬆️
process.time_to_main_ms472.04 ± (471.46 - 472.62) ms472.67 ± (472.14 - 473.20) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.10 ± (48.08 - 48.12) MB48.10 ± (48.08 - 48.12) MB-0.0%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.0%
.NET 6 - Baseline
process.internal_duration_ms20.65 ± (20.63 - 20.68) ms20.66 ± (20.62 - 20.69) ms+0.0%✅⬆️
process.time_to_main_ms68.09 ± (67.97 - 68.20) ms68.12 ± (67.99 - 68.25) ms+0.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.61 ± (10.61 - 10.61) MB10.63 ± (10.62 - 10.63) MB+0.2%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms20.61 ± (20.58 - 20.64) ms20.58 ± (20.56 - 20.60) ms-0.1%
process.time_to_main_ms68.94 ± (68.88 - 69.01) ms68.92 ± (68.87 - 68.98) ms-0.0%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.74 ± (10.73 - 10.74) MB10.66 ± (10.66 - 10.67) MB-0.7%
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms200.18 ± (198.87 - 201.49) ms201.09 ± (200.03 - 202.16) ms+0.5%✅⬆️
process.time_to_main_ms437.61 ± (436.97 - 438.24) ms439.41 ± (438.78 - 440.03) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.00 ± (47.92 - 48.08) MB48.30 ± (48.24 - 48.37) MB+0.6%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.2%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms18.82 ± (18.79 - 18.84) ms18.97 ± (18.94 - 19.00) ms+0.8%✅⬆️
process.time_to_main_ms66.98 ± (66.87 - 67.08) ms67.25 ± (67.14 - 67.35) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.69 ± (7.68 - 7.70) MB7.66 ± (7.66 - 7.67) MB-0.3%
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms18.81 ± (18.79 - 18.82) ms18.90 ± (18.87 - 18.93) ms+0.5%✅⬆️
process.time_to_main_ms68.07 ± (68.01 - 68.13) ms68.36 ± (68.26 - 68.46) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.73 ± (7.72 - 7.74) MB7.72 ± (7.71 - 7.73) MB-0.1%
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms180.15 ± (179.10 - 181.20) ms178.86 ± (178.06 - 179.66) ms-0.7%
process.time_to_main_ms425.59 ± (424.81 - 426.37) ms423.15 ± (422.69 - 423.61) ms-0.6%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.31 ± (36.27 - 36.34) MB36.28 ± (36.24 - 36.31) MB-0.1%
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
duration192.71 ± (193.01 - 193.77) ms192.93 ± (193.00 - 193.81) ms+0.1%✅⬆️
.NET Framework 4.8 - Bailout
duration196.49 ± (196.15 - 196.64) ms196.41 ± (196.32 - 196.81) ms-0.0%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1111.56 ± (1114.95 - 1123.79) ms1106.94 ± (1110.17 - 1118.15) ms-0.4%
.NET Core 3.1 - Baseline
process.internal_duration_ms187.49 ± (187.10 - 187.89) ms187.82 ± (187.45 - 188.20) ms+0.2%✅⬆️
process.time_to_main_ms80.17 ± (79.97 - 80.38) ms80.67 ± (80.49 - 80.85) ms+0.6%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.06 ± (16.04 - 16.09) MB16.13 ± (16.11 - 16.16) MB+0.4%✅⬆️
runtime.dotnet.threads.count20 ± (19 - 20)20 ± (19 - 20)-0.1%
.NET Core 3.1 - Bailout
process.internal_duration_ms186.68 ± (186.37 - 187.00) ms186.88 ± (186.59 - 187.18) ms+0.1%✅⬆️
process.time_to_main_ms81.54 ± (81.42 - 81.65) ms81.63 ± (81.47 - 81.79) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.16 ± (16.13 - 16.19) MB16.25 ± (16.20 - 16.30) MB+0.5%✅⬆️
runtime.dotnet.threads.count21 ± (21 - 21)21 ± (21 - 21)+0.5%✅⬆️
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms395.98 ± (393.57 - 398.40) ms396.91 ± (394.02 - 399.79) ms+0.2%✅⬆️
process.time_to_main_ms475.83 ± (475.22 - 476.43) ms474.76 ± (474.07 - 475.46) ms-0.2%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed58.48 ± (58.33 - 58.62) MB58.40 ± (58.26 - 58.55) MB-0.1%
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 30)+0.0%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms191.69 ± (191.34 - 192.03) ms191.99 ± (191.65 - 192.34) ms+0.2%✅⬆️
process.time_to_main_ms69.73 ± (69.57 - 69.90) ms69.85 ± (69.66 - 70.05) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.04 ± (15.90 - 16.18) MB16.26 ± (16.17 - 16.36) MB+1.4%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 19)19 ± (19 - 19)+2.9%✅⬆️
.NET 6 - Bailout
process.internal_duration_ms190.64 ± (190.43 - 190.86) ms190.80 ± (190.54 - 191.06) ms+0.1%✅⬆️
process.time_to_main_ms70.36 ± (70.28 - 70.43) ms70.52 ± (70.43 - 70.61) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.11 ± (15.97 - 16.26) MB15.99 ± (15.83 - 16.16) MB-0.7%
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)-0.2%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms411.54 ± (408.95 - 414.13) ms409.37 ± (407.21 - 411.52) ms-0.5%
process.time_to_main_ms443.81 ± (443.28 - 444.33) ms444.28 ± (443.78 - 444.78) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed59.01 ± (58.88 - 59.14) MB59.14 ± (59.01 - 59.27) MB+0.2%✅⬆️
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (29 - 30)-0.3%
.NET 8 - Baseline
process.internal_duration_ms189.64 ± (189.37 - 189.91) ms189.99 ± (189.67 - 190.32) ms+0.2%✅⬆️
process.time_to_main_ms69.26 ± (69.04 - 69.48) ms69.50 ± (69.29 - 69.71) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.70 ± (11.64 - 11.75) MB11.75 ± (11.73 - 11.77) MB+0.5%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)+1.8%✅⬆️
.NET 8 - Bailout
process.internal_duration_ms189.20 ± (188.95 - 189.45) ms189.46 ± (189.18 - 189.74) ms+0.1%✅⬆️
process.time_to_main_ms70.22 ± (70.12 - 70.32) ms70.48 ± (70.38 - 70.59) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.80 ± (11.75 - 11.84) MB11.90 ± (11.87 - 11.93) MB+0.9%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)-0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms362.33 ± (360.62 - 364.04) ms362.43 ± (360.89 - 363.97) ms+0.0%✅⬆️
process.time_to_main_ms426.00 ± (425.47 - 426.54) ms427.61 ± (427.09 - 428.13) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed47.95 ± (47.92 - 47.98) MB47.95 ± (47.93 - 47.98) MB+0.0%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)+0.3%✅⬆️
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 (7986) - mean (69ms)  : 67, 70
    master - mean (69ms)  : 67, 70

    section Bailout
    This PR (7986) - mean (72ms)  : 71, 73
    master - mean (72ms)  : 71, 73

    section CallTarget+Inlining+NGEN
    This PR (7986) - mean (1,009ms)  : 959, 1058
    master - mean (1,008ms)  : 959, 1058

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 (7986) - mean (106ms)  : 103, 108
    master - mean (106ms)  : 103, 108

    section Bailout
    This PR (7986) - mean (107ms)  : 105, 108
    master - mean (107ms)  : 106, 108

    section CallTarget+Inlining+NGEN
    This PR (7986) - mean (711ms)  : 684, 737
    master - mean (709ms)  : 681, 738

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

    section Bailout
    This PR (7986) - mean (94ms)  : 93, 95
    master - mean (94ms)  : 93, 95

    section CallTarget+Inlining+NGEN
    This PR (7986) - mean (667ms)  : 643, 691
    master - mean (663ms)  : 644, 683

Loading
FakeDbCommand (.NET 8)
gantt
    title Execution time (ms) FakeDbCommand (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7986) - mean (92ms)  : 90, 95
    master - mean (92ms)  : 90, 94

    section Bailout
    This PR (7986) - mean (93ms)  : 91, 95
    master - mean (93ms)  : 92, 94

    section CallTarget+Inlining+NGEN
    This PR (7986) - mean (632ms)  : 613, 650
    master - mean (634ms)  : 619, 648

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 (7986) - mean (193ms)  : 189, 198
    master - mean (193ms)  : 189, 197

    section Bailout
    This PR (7986) - mean (197ms)  : 194, 199
    master - mean (196ms)  : 194, 199

    section CallTarget+Inlining+NGEN
    This PR (7986) - mean (1,114ms)  : 1055, 1174
    master - mean (1,119ms)  : 1052, 1186

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 (7986) - mean (277ms)  : 272, 282
    master - mean (276ms)  : 270, 282

    section Bailout
    This PR (7986) - mean (277ms)  : 273, 281
    master - mean (276ms)  : 273, 280

    section CallTarget+Inlining+NGEN
    This PR (7986) - mean (911ms)  : 860, 962
    master - mean (904ms)  : 856, 952

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7986) - mean (270ms)  : 266, 275
    master - mean (270ms)  : 265, 275

    section Bailout
    This PR (7986) - mean (269ms)  : 266, 273
    master - mean (269ms)  : 266, 272

    section CallTarget+Inlining+NGEN
    This PR (7986) - mean (888ms)  : 848, 928
    master - mean (885ms)  : 847, 923

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7986) - mean (269ms)  : 264, 274
    master - mean (268ms)  : 264, 273

    section Bailout
    This PR (7986) - mean (269ms)  : 266, 273
    master - mean (269ms)  : 266, 272

    section CallTarget+Inlining+NGEN
    This PR (7986) - mean (822ms)  : 798, 846
    master - mean (820ms)  : 801, 839

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:debugger area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants