Skip to content

[EL] DEBUG-4884 Fix null expression when type is struct#7993

Merged
dudikeleti merged 4 commits intomasterfrom
dudik/el-safe-cast-box-null
Jan 21, 2026
Merged

[EL] DEBUG-4884 Fix null expression when type is struct#7993
dudikeleti merged 4 commits intomasterfrom
dudik/el-safe-cast-box-null

Conversation

@dudikeleti
Copy link
Contributor

@dudikeleti dudikeleti commented Dec 20, 2025

Summary of changes

Prevent null-unboxing failures when binding ScopeMember.Value into value-type locals during probe expression compilation.

Reason for change

When the target variable type is a non-nullable value type (struct), Expression.Convert(valueField, type) attempts to unbox null, which throws at execution time. This caused probe evaluation to fail even when a safe default value would be acceptable.

Implementation details

  • Build the assignment expression differently for value types vs reference types:
    • Value types: emit a conditional expression:
      • if ScopeMember.Value == null → assign default(TValue)
      • else → unbox via Convert(object, TValue)
    • Reference types: keep the existing Convert, which already handles null correctly.
  • This change keeps behavior unchanged for valid values and avoids runtime NullReferenceException for null value-type bindings.

Test coverage

Snapshot Exploration Test
ProbeTests.RecursionWithInnerRefStructTest
ProbeExpressionParser_ValueTypeNull_UsesDefaultValue

Other details

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

@dudikeleti dudikeleti requested a review from a team as a code owner December 20, 2025 13:24
@github-actions github-actions bot added area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) area:debugger labels Dec 20, 2025
@datadog-official

This comment has been minimized.

@pr-commenter
Copy link

pr-commenter bot commented Jan 7, 2026

Benchmarks

Benchmark execution time: 2026-01-07 15:56:11

Comparing candidate commit 0ec0aa0 in PR branch dudik/el-safe-cast-box-null with baseline commit 79f4ccc in branch master.

Found 7 performance improvements and 10 performance regressions! Performance is the same for 162 metrics, 7 unstable metrics.

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

  • 🟥 execution_time [+10.014ms; +15.547ms] or [+5.169%; +8.025%]

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

  • 🟩 execution_time [-101.556ms; -97.220ms] or [-51.842%; -49.629%]

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

  • 🟥 execution_time [+14.838ms; +20.967ms] or [+7.533%; +10.644%]

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

  • 🟥 execution_time [+14.023ms; +19.323ms] or [+7.043%; +9.705%]

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

  • 🟥 execution_time [+27.735ms; +27.931ms] or [+15.827%; +15.939%]

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

  • 🟥 throughput [-365.736op/s; -326.944op/s] or [-7.233%; -6.466%]

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

  • 🟥 execution_time [+41.993ms; +43.910ms] or [+45.172%; +47.233%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟩 execution_time [-24.825ms; -18.063ms] or [-10.664%; -7.760%]

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

  • 🟥 throughput [-248.428op/s; -162.059op/s] or [-16.258%; -10.606%]

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

  • 🟩 execution_time [-122.462µs; -113.632µs] or [-8.120%; -7.535%]
  • 🟩 throughput [+54.252op/s; +58.350op/s] or [+8.182%; +8.800%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net472

  • 🟥 execution_time [+64.342µs; +69.192µs] or [+5.685%; +6.114%]
  • 🟥 throughput [-50.994op/s; -47.444op/s] or [-5.771%; -5.370%]

scenario:Benchmarks.Trace.DbCommandBenchmark.ExecuteNonQuery net472

  • 🟩 throughput [+18566.692op/s; +20639.610op/s] or [+5.218%; +5.800%]

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

  • 🟥 throughput [-388.743op/s; -206.322op/s] or [-17.979%; -9.542%]

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

  • 🟩 execution_time [-19.982ms; -14.340ms] or [-9.259%; -6.645%]

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

  • 🟩 execution_time [-12.966ms; -11.508ms] or [-6.126%; -5.437%]

Copy link
Contributor

@GreenMatan GreenMatan left a comment

Choose a reason for hiding this comment

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

left a comment

@dudikeleti dudikeleti force-pushed the dudik/el-safe-cast-box-null branch from 0ec0aa0 to 5d12f5e Compare January 20, 2026 23:12
@github-actions
Copy link
Contributor

Snapshots difference summary

The following differences have been observed in committed snapshots. It is meant to help the reviewer.
The diff is simplistic, so please check some files anyway while we improve it.

10 occurrences of :

-        "evaluationErrors": [
-          {
-            "expr": "\"1\")",
-            "message": "ScrubbedValue"
-          }
-        ],

@dd-trace-dotnet-ci-bot
Copy link

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

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (7993) 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
duration73.35 ± (73.30 - 73.68) ms72.77 ± (73.00 - 73.52) ms-0.8%
.NET Framework 4.8 - Bailout
duration76.59 ± (76.51 - 76.99) ms76.93 ± (76.52 - 77.02) ms+0.4%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1042.02 ± (1042.17 - 1050.24) ms1035.01 ± (1037.89 - 1047.11) ms-0.7%
.NET Core 3.1 - Baseline
process.internal_duration_ms22.51 ± (22.46 - 22.57) ms22.30 ± (22.25 - 22.34) ms-1.0%
process.time_to_main_ms84.86 ± (84.60 - 85.11) ms83.64 ± (83.43 - 83.84) ms-1.4%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.91 ± (10.91 - 10.92) MB10.90 ± (10.90 - 10.91) MB-0.1%
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms22.45 ± (22.41 - 22.50) ms22.40 ± (22.36 - 22.44) ms-0.2%
process.time_to_main_ms86.65 ± (86.46 - 86.84) ms85.76 ± (85.56 - 85.96) ms-1.0%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.94 ± (10.94 - 10.94) MB10.94 ± (10.94 - 10.95) MB+0.0%✅⬆️
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms243.57 ± (239.65 - 247.49) ms245.82 ± (241.84 - 249.80) ms+0.9%✅⬆️
process.time_to_main_ms488.60 ± (487.23 - 489.96) ms490.00 ± (488.65 - 491.36) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.29 ± (48.26 - 48.31) MB48.27 ± (48.25 - 48.30) MB-0.0%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.0%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms21.09 ± (21.06 - 21.13) ms21.42 ± (21.38 - 21.46) ms+1.6%✅⬆️
process.time_to_main_ms72.50 ± (72.30 - 72.70) ms74.03 ± (73.81 - 74.25) ms+2.1%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.62 ± (10.62 - 10.62) MB10.62 ± (10.62 - 10.63) MB+0.0%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms21.14 ± (21.10 - 21.18) ms21.15 ± (21.11 - 21.18) ms+0.0%✅⬆️
process.time_to_main_ms74.50 ± (74.29 - 74.71) ms74.04 ± (73.87 - 74.21) ms-0.6%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.70 ± (10.69 - 10.70) MB10.72 ± (10.72 - 10.72) MB+0.2%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms232.28 ± (228.35 - 236.20) ms239.77 ± (235.93 - 243.60) ms+3.2%✅⬆️
process.time_to_main_ms465.95 ± (464.65 - 467.24) ms464.27 ± (463.07 - 465.47) ms-0.4%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed49.10 ± (49.07 - 49.13) MB49.14 ± (49.11 - 49.16) MB+0.1%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.3%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms19.29 ± (19.24 - 19.35) ms19.44 ± (19.39 - 19.50) ms+0.8%✅⬆️
process.time_to_main_ms72.36 ± (72.15 - 72.57) ms72.73 ± (72.52 - 72.94) ms+0.5%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.65 ± (7.65 - 7.66) MB7.66 ± (7.65 - 7.66) MB+0.1%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms19.34 ± (19.31 - 19.38) ms19.46 ± (19.42 - 19.50) ms+0.6%✅⬆️
process.time_to_main_ms74.03 ± (73.83 - 74.23) ms73.98 ± (73.82 - 74.14) ms-0.1%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.73 ± (7.73 - 7.74) MB7.71 ± (7.71 - 7.72) MB-0.3%
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms186.22 ± (185.49 - 186.94) ms186.03 ± (185.23 - 186.84) ms-0.1%
process.time_to_main_ms444.53 ± (443.45 - 445.60) ms447.69 ± (446.46 - 448.91) ms+0.7%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.66 ± (36.63 - 36.69) MB36.69 ± (36.66 - 36.72) MB+0.1%✅⬆️
runtime.dotnet.threads.count27 ± (27 - 27)27 ± (27 - 27)-0.5%

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration197.42 ± (197.22 - 198.04) ms193.58 ± (193.49 - 194.36) ms-1.9%
.NET Framework 4.8 - Bailout
duration199.53 ± (199.49 - 200.17) ms197.00 ± (196.75 - 197.33) ms-1.3%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1139.19 ± (1139.68 - 1148.54) ms1123.21 ± (1129.68 - 1139.09) ms-1.4%
.NET Core 3.1 - Baseline
process.internal_duration_ms191.44 ± (191.01 - 191.87) ms187.70 ± (187.33 - 188.07) ms-2.0%
process.time_to_main_ms82.79 ± (82.52 - 83.05) ms81.20 ± (81.02 - 81.38) ms-1.9%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.03 ± (16.01 - 16.05) MB16.06 ± (16.03 - 16.08) MB+0.2%✅⬆️
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (19 - 20)-0.2%
.NET Core 3.1 - Bailout
process.internal_duration_ms191.75 ± (191.28 - 192.23) ms187.15 ± (186.81 - 187.49) ms-2.4%
process.time_to_main_ms84.58 ± (84.34 - 84.82) ms82.48 ± (82.31 - 82.64) ms-2.5%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.12 ± (16.09 - 16.14) MB16.15 ± (16.12 - 16.18) MB+0.2%✅⬆️
runtime.dotnet.threads.count21 ± (21 - 21)21 ± (20 - 21)-0.1%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms426.02 ± (422.34 - 429.70) ms422.34 ± (419.16 - 425.52) ms-0.9%
process.time_to_main_ms478.68 ± (477.87 - 479.49) ms473.37 ± (472.82 - 473.92) ms-1.1%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed58.86 ± (58.75 - 58.96) MB58.87 ± (58.76 - 58.99) MB+0.0%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 30)29 ± (29 - 29)-0.0%
.NET 6 - Baseline
process.internal_duration_ms193.96 ± (193.50 - 194.43) ms191.17 ± (190.92 - 191.43) ms-1.4%
process.time_to_main_ms71.43 ± (71.25 - 71.62) ms70.17 ± (69.98 - 70.36) ms-1.8%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.38 ± (16.36 - 16.41) MB15.97 ± (15.82 - 16.12) MB-2.5%
runtime.dotnet.threads.count19 ± (19 - 19)18 ± (18 - 18)-4.5%
.NET 6 - Bailout
process.internal_duration_ms195.63 ± (195.15 - 196.11) ms190.89 ± (190.58 - 191.21) ms-2.4%
process.time_to_main_ms72.73 ± (72.53 - 72.94) ms71.06 ± (70.92 - 71.19) ms-2.3%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.40 ± (16.37 - 16.43) MB16.31 ± (16.21 - 16.42) MB-0.5%
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)-2.1%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms442.93 ± (439.49 - 446.36) ms438.12 ± (434.57 - 441.67) ms-1.1%
process.time_to_main_ms457.99 ± (457.18 - 458.80) ms452.12 ± (451.50 - 452.74) ms-1.3%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed59.11 ± (58.97 - 59.24) MB59.00 ± (58.87 - 59.14) MB-0.2%
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)-0.0%
.NET 8 - Baseline
process.internal_duration_ms191.19 ± (190.79 - 191.58) ms190.86 ± (190.52 - 191.21) ms-0.2%
process.time_to_main_ms71.00 ± (70.75 - 71.24) ms70.33 ± (70.12 - 70.54) ms-0.9%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.70 ± (11.67 - 11.73) MB11.70 ± (11.68 - 11.73) MB+0.0%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)-0.0%
.NET 8 - Bailout
process.internal_duration_ms191.79 ± (191.32 - 192.25) ms189.41 ± (189.15 - 189.67) ms-1.2%
process.time_to_main_ms72.35 ± (72.17 - 72.52) ms71.48 ± (71.35 - 71.61) ms-1.2%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.75 ± (11.72 - 11.77) MB11.77 ± (11.75 - 11.80) MB+0.2%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)-0.1%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms369.75 ± (368.23 - 371.28) ms367.59 ± (366.16 - 369.02) ms-0.6%
process.time_to_main_ms437.22 ± (436.56 - 437.88) ms436.55 ± (435.86 - 437.25) ms-0.2%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed48.19 ± (48.15 - 48.22) MB48.17 ± (48.13 - 48.20) MB-0.0%
runtime.dotnet.threads.count29 ± (29 - 29)28 ± (28 - 29)-1.4%
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 (7993) - mean (73ms)  : 70, 77
    master - mean (73ms)  : 71, 76

    section Bailout
    This PR (7993) - mean (77ms)  : 73, 81
    master - mean (77ms)  : 74, 80

    section CallTarget+Inlining+NGEN
    This PR (7993) - mean (1,042ms)  : 976, 1109
    master - mean (1,046ms)  : 987, 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 (7993) - mean (112ms)  : 107, 117
    master - mean (114ms)  : 109, 119

    section Bailout
    This PR (7993) - mean (115ms)  : 110, 119
    master - mean (116ms)  : 112, 120

    section CallTarget+Inlining+NGEN
    This PR (7993) - mean (773ms)  : 696, 849
    master - mean (769ms)  : 705, 832

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7993) - mean (102ms)  : 98, 105
    master - mean (100ms)  : 95, 104

    section Bailout
    This PR (7993) - mean (101ms)  : 97, 105
    master - mean (102ms)  : 97, 106

    section CallTarget+Inlining+NGEN
    This PR (7993) - mean (733ms)  : 658, 808
    master - mean (731ms)  : 669, 794

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

    section Bailout
    This PR (7993) - mean (101ms)  : 97, 105
    master - mean (101ms)  : 97, 105

    section CallTarget+Inlining+NGEN
    This PR (7993) - mean (665ms)  : 634, 695
    master - mean (661ms)  : 631, 690

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 (7993) - mean (194ms)  : 190, 198
    master - mean (198ms)  : 192, 203

    section Bailout
    This PR (7993) - mean (197ms)  : 194, 200
    master - mean (200ms)  : 197, 203

    section CallTarget+Inlining+NGEN
    This PR (7993) - mean (1,134ms)  : 1067, 1202
    master - mean (1,144ms)  : 1079, 1209

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 (7993) - mean (277ms)  : 271, 283
    master - mean (284ms)  : 272, 296

    section Bailout
    This PR (7993) - mean (278ms)  : 274, 282
    master - mean (285ms)  : 277, 294

    section CallTarget+Inlining+NGEN
    This PR (7993) - mean (929ms)  : 885, 972
    master - mean (939ms)  : 887, 990

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7993) - mean (269ms)  : 265, 274
    master - mean (274ms)  : 268, 279

    section Bailout
    This PR (7993) - mean (270ms)  : 265, 275
    master - mean (277ms)  : 269, 285

    section CallTarget+Inlining+NGEN
    This PR (7993) - mean (920ms)  : 865, 974
    master - mean (939ms)  : 887, 991

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7993) - mean (271ms)  : 265, 278
    master - mean (272ms)  : 267, 278

    section Bailout
    This PR (7993) - mean (270ms)  : 266, 275
    master - mean (274ms)  : 268, 280

    section CallTarget+Inlining+NGEN
    This PR (7993) - mean (836ms)  : 817, 855
    master - mean (838ms)  : 815, 860

Loading

@dudikeleti dudikeleti force-pushed the dudik/el-safe-cast-box-null branch from 5d12f5e to 854b5c3 Compare January 21, 2026 00:05
@dudikeleti dudikeleti enabled auto-merge (squash) January 21, 2026 00:07
@dudikeleti dudikeleti merged commit a655a8d into master Jan 21, 2026
152 of 153 checks passed
@dudikeleti dudikeleti deleted the dudik/el-safe-cast-box-null branch January 21, 2026 01:33
@github-actions github-actions bot added this to the vNext-v3 milestone Jan 21, 2026
dudikeleti added a commit that referenced this pull request Jan 21, 2026
## Summary of changes
- Reworked `ProbeExpressionEvaluator` to cache compiled expressions
**per runtime type combination** (invocation target, return value, and
scope members), instead of a single `Lazy<>` instance shared across all
invocations.
- Introduced `ExpressionCacheKey` to uniquely identify a compilation
context using **runtime types** (`Value.GetType()` when available) and
member runtime types to support polymorphic calls.
- Replaced single cached fields with
`ConcurrentDictionary<ExpressionCacheKey, …>` caches for:
  - Templates (`CompiledExpression<string>[]?`)
  - Condition (`CompiledExpression<bool>?`)
  - Metric (`CompiledExpression<double>?`)
  - Span decorations (compiled decorations array)
- Preserved evaluation semantics and error aggregation, while ensuring
compiled delegates match the actual runtime types.

## Reason for change
The previous implementation compiled expressions once (on first
invocation) and reused them for all subsequent calls. This fails in
polymorphic scenarios where:
- The declared type differs from the runtime type (e.g., generics/base
class/interface method invoked on a derived instance).
- Parameters/locals are declared as a base type (or `object`) but carry
different concrete runtime types across invocations.

In these cases, delegates compiled against the first observed type can
fail later (typically invalid casts / expression binding mismatches),
causing evaluation errors and incorrect probe results.

## Implementation details
- Compute a **runtime-aware cache key** on each `Evaluate()` call:
- `thisType`: `InvocationTarget.Value?.GetType()` (fallback to declared
type, then `typeof(object)`)
  - `returnType`: `Return.Value?.GetType()` (fallback to declared type)
- `members`: runtime types captured from `ScopeMember.Value?.GetType()`
(fallback to declared `ScopeMember.Type`)
- Store compiled artifacts in thread-safe caches:
  - `ConcurrentDictionary<ExpressionCacheKey, ...>`
  - On cache miss: compile, then `TryAdd`
- Added `ExpressionCacheKey` struct:
- Precomputes hash over `thisType`, `returnType`, and member runtime
types.
- Implements equality by comparing `ThisType`, `ReturnType`, and the
captured member type sequence (hash used as a fast-path).
- Added debug logging for cache misses (type + hash + cache size) to
help diagnose compilation churn and verify caching behavior.

## Test coverage
- Existing `DebuggerExpressionLanguageTests` remain supported via
`CompiledTemplates` / `CompiledCondition` accessors (now returning the
first cached entry).
- Snapshot Exploration Test

## Dependencies
- Depends on: #7991, #7992, #7993
- Merge order: #7991#7992#7993 → (this PR)

## Other details
- Caches may grow with many unique type combinations; however this is
required for correctness under polymorphic workloads. If needed later,
we can add eviction/size caps.
- This PR is part of an effort to make the Snapshot Exploration Test run
successfully end-to-end.
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.

3 participants