Skip to content

[EL] DEBUG-4878 Fix null equality in expression language#7991

Merged
dudikeleti merged 3 commits intomasterfrom
dudik/el-fix-null-equality
Jan 20, 2026
Merged

[EL] DEBUG-4878 Fix null equality in expression language#7991
dudikeleti merged 3 commits intomasterfrom
dudik/el-fix-null-equality

Conversation

@dudikeleti
Copy link
Contributor

@dudikeleti dudikeleti commented Dec 20, 2025

Summary of changes

Harden binary equality handling (== / !=) in the probe expression parser to avoid runtime exceptions and produce predictable results when comparing:

  • non-nullable value types to null
  • reference types to null when the runtime type differs from the compile-time type

Implementation details

  • Route == and != through a dedicated EqualExpression() helper.
  • For non-nullable value type vs null:
    • return a constant expression (false for ==, true for !=) since the comparison outcome is deterministic.
  • For reference type vs null:
    • use Expression.ReferenceEqual on object-converted operands to ensure object-reference semantics and avoid type-cast issues.

Test coverage

Snapshot Exploration Test
ProbeExpressionParser_NonNullableValueTypeComparedToNull_DoesNotThrow

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:02
@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-datadog-prod-us1

This comment has been minimized.

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

dd-trace-dotnet-ci-bot bot commented Dec 20, 2025

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (7991) 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.78 ± (72.68 - 73.10) ms-0.8%
.NET Framework 4.8 - Bailout
duration76.59 ± (76.51 - 76.99) ms77.54 ± (77.45 - 77.78) ms+1.2%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1042.02 ± (1042.17 - 1050.24) ms1031.03 ± (1034.62 - 1042.91) ms-1.1%
.NET Core 3.1 - Baseline
process.internal_duration_ms22.51 ± (22.46 - 22.57) ms22.42 ± (22.37 - 22.47) ms-0.4%
process.time_to_main_ms84.86 ± (84.60 - 85.11) ms84.54 ± (84.28 - 84.79) ms-0.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.29 ± (22.25 - 22.33) ms-0.7%
process.time_to_main_ms86.65 ± (86.46 - 86.84) ms86.04 ± (85.84 - 86.25) ms-0.7%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.94 ± (10.94 - 10.94) MB10.94 ± (10.93 - 10.94) 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) ms248.10 ± (244.23 - 251.96) ms+1.9%✅⬆️
process.time_to_main_ms488.60 ± (487.23 - 489.96) ms486.35 ± (485.04 - 487.66) ms-0.5%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.29 ± (48.26 - 48.31) MB48.31 ± (48.29 - 48.33) MB+0.1%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.1%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms21.09 ± (21.06 - 21.13) ms21.15 ± (21.11 - 21.19) ms+0.3%✅⬆️
process.time_to_main_ms72.50 ± (72.30 - 72.70) ms73.48 ± (73.29 - 73.68) ms+1.4%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.62 ± (10.62 - 10.62) MB10.63 ± (10.63 - 10.64) MB+0.2%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms21.14 ± (21.10 - 21.18) ms21.23 ± (21.19 - 21.27) ms+0.4%✅⬆️
process.time_to_main_ms74.50 ± (74.29 - 74.71) ms75.08 ± (74.86 - 75.30) ms+0.8%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.70 ± (10.69 - 10.70) MB10.73 ± (10.72 - 10.73) MB+0.3%✅⬆️
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) ms237.07 ± (233.10 - 241.05) ms+2.1%✅⬆️
process.time_to_main_ms465.95 ± (464.65 - 467.24) ms470.41 ± (468.89 - 471.92) ms+1.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed49.10 ± (49.07 - 49.13) MB49.02 ± (49.00 - 49.05) MB-0.2%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.3%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms19.29 ± (19.24 - 19.35) ms19.31 ± (19.28 - 19.35) ms+0.1%✅⬆️
process.time_to_main_ms72.36 ± (72.15 - 72.57) ms72.30 ± (72.10 - 72.51) ms-0.1%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.65 ± (7.65 - 7.66) MB7.65 ± (7.64 - 7.65) 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.35 ± (19.31 - 19.38) ms+0.0%✅⬆️
process.time_to_main_ms74.03 ± (73.83 - 74.23) ms73.76 ± (73.59 - 73.94) ms-0.4%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.73 ± (7.73 - 7.74) MB7.71 ± (7.70 - 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) ms185.12 ± (184.23 - 186.00) ms-0.6%
process.time_to_main_ms444.53 ± (443.45 - 445.60) ms444.70 ± (443.75 - 445.65) ms+0.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.66 ± (36.63 - 36.69) MB36.66 ± (36.63 - 36.70) MB+0.0%✅⬆️
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
duration197.42 ± (197.22 - 198.04) ms193.23 ± (193.24 - 194.03) ms-2.1%
.NET Framework 4.8 - Bailout
duration199.53 ± (199.49 - 200.17) ms197.27 ± (197.22 - 197.82) ms-1.1%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1139.19 ± (1139.68 - 1148.54) ms1123.44 ± (1127.01 - 1135.34) ms-1.4%
.NET Core 3.1 - Baseline
process.internal_duration_ms191.44 ± (191.01 - 191.87) ms187.61 ± (187.32 - 187.91) ms-2.0%
process.time_to_main_ms82.79 ± (82.52 - 83.05) ms81.41 ± (81.18 - 81.65) ms-1.7%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.03 ± (16.01 - 16.05) MB16.07 ± (16.05 - 16.10) MB+0.3%✅⬆️
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (19 - 20)-0.3%
.NET Core 3.1 - Bailout
process.internal_duration_ms191.75 ± (191.28 - 192.23) ms187.55 ± (187.14 - 187.97) ms-2.2%
process.time_to_main_ms84.58 ± (84.34 - 84.82) ms82.67 ± (82.50 - 82.84) ms-2.3%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.12 ± (16.09 - 16.14) MB16.14 ± (16.11 - 16.17) MB+0.2%✅⬆️
runtime.dotnet.threads.count21 ± (21 - 21)21 ± (21 - 21)+0.9%✅⬆️
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms426.02 ± (422.34 - 429.70) ms432.71 ± (428.68 - 436.75) ms+1.6%✅⬆️
process.time_to_main_ms478.68 ± (477.87 - 479.49) ms472.73 ± (471.94 - 473.51) ms-1.2%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed58.86 ± (58.75 - 58.96) MB58.58 ± (58.42 - 58.75) MB-0.5%
runtime.dotnet.threads.count29 ± (29 - 30)29 ± (29 - 29)-0.1%
.NET 6 - Baseline
process.internal_duration_ms193.96 ± (193.50 - 194.43) ms193.18 ± (192.85 - 193.52) ms-0.4%
process.time_to_main_ms71.43 ± (71.25 - 71.62) ms71.23 ± (71.01 - 71.46) ms-0.3%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.38 ± (16.36 - 16.41) MB16.30 ± (16.21 - 16.38) MB-0.5%
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)-0.5%
.NET 6 - Bailout
process.internal_duration_ms195.63 ± (195.15 - 196.11) ms191.51 ± (191.25 - 191.76) ms-2.1%
process.time_to_main_ms72.73 ± (72.53 - 72.94) ms71.63 ± (71.51 - 71.75) ms-1.5%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.40 ± (16.37 - 16.43) MB15.99 ± (15.83 - 16.15) MB-2.5%
runtime.dotnet.threads.count20 ± (20 - 20)19 ± (19 - 19)-5.4%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms442.93 ± (439.49 - 446.36) ms438.53 ± (435.04 - 442.03) ms-1.0%
process.time_to_main_ms457.99 ± (457.18 - 458.80) ms453.48 ± (452.95 - 454.00) ms-1.0%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed59.11 ± (58.97 - 59.24) MB59.07 ± (58.93 - 59.20) MB-0.1%
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)+0.0%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms191.19 ± (190.79 - 191.58) ms190.65 ± (190.25 - 191.06) ms-0.3%
process.time_to_main_ms71.00 ± (70.75 - 71.24) ms70.38 ± (70.18 - 70.59) ms-0.9%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.70 ± (11.67 - 11.73) MB11.75 ± (11.72 - 11.78) MB+0.4%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)+0.1%✅⬆️
.NET 8 - Bailout
process.internal_duration_ms191.79 ± (191.32 - 192.25) ms189.68 ± (189.41 - 189.96) ms-1.1%
process.time_to_main_ms72.35 ± (72.17 - 72.52) ms70.99 ± (70.84 - 71.13) ms-1.9%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.75 ± (11.72 - 11.77) MB11.86 ± (11.83 - 11.89) MB+1.0%✅⬆️
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) ms364.55 ± (362.88 - 366.21) ms-1.4%
process.time_to_main_ms437.22 ± (436.56 - 437.88) ms435.57 ± (434.96 - 436.19) ms-0.4%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed48.19 ± (48.15 - 48.22) MB48.19 ± (48.15 - 48.24) MB+0.0%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)-0.2%
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 (7991) - mean (73ms)  : 70, 76
    master - mean (73ms)  : 71, 76

    section Bailout
    This PR (7991) - mean (78ms)  : 75, 80
    master - mean (77ms)  : 74, 80

    section CallTarget+Inlining+NGEN
    This PR (7991) - mean (1,039ms)  : 978, 1099
    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 (7991) - mean (114ms)  : 108, 119
    master - mean (114ms)  : 109, 119

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

    section CallTarget+Inlining+NGEN
    This PR (7991) - mean (767ms)  : 697, 836
    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 (7991) - mean (101ms)  : 97, 105
    master - mean (100ms)  : 95, 104

    section Bailout
    This PR (7991) - mean (102ms)  : 97, 107
    master - mean (102ms)  : 97, 106

    section CallTarget+Inlining+NGEN
    This PR (7991) - mean (739ms)  : 658, 820
    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 (7991) - mean (99ms)  : 96, 103
    master - mean (99ms)  : 95, 103

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

    section CallTarget+Inlining+NGEN
    This PR (7991) - mean (662ms)  : 633, 690
    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 (7991) - mean (194ms)  : 190, 197
    master - mean (198ms)  : 192, 203

    section Bailout
    This PR (7991) - mean (198ms)  : 195, 200
    master - mean (200ms)  : 197, 203

    section CallTarget+Inlining+NGEN
    This PR (7991) - mean (1,131ms)  : 1071, 1191
    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 (7991) - mean (277ms)  : 273, 282
    master - mean (284ms)  : 272, 296

    section Bailout
    This PR (7991) - mean (279ms)  : 274, 284
    master - mean (285ms)  : 277, 294

    section CallTarget+Inlining+NGEN
    This PR (7991) - mean (934ms)  : 889, 978
    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 (7991) - mean (273ms)  : 268, 277
    master - mean (274ms)  : 268, 279

    section Bailout
    This PR (7991) - mean (272ms)  : 268, 275
    master - mean (277ms)  : 269, 285

    section CallTarget+Inlining+NGEN
    This PR (7991) - mean (924ms)  : 876, 973
    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 (7991) - mean (271ms)  : 265, 278
    master - mean (272ms)  : 267, 278

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

    section CallTarget+Inlining+NGEN
    This PR (7991) - mean (830ms)  : 814, 846
    master - mean (838ms)  : 815, 860

Loading

@dudikeleti dudikeleti force-pushed the dudik/el-fix-null-equality branch from 57d0c9b to e0ca6a7 Compare January 7, 2026 14:59
@pr-commenter
Copy link

pr-commenter bot commented Jan 7, 2026

Benchmarks

Benchmark execution time: 2026-01-07 16:02:30

Comparing candidate commit e0ca6a7 in PR branch dudik/el-fix-null-equality with baseline commit 5d1df24 in branch master.

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

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

  • 🟩 execution_time [-104.721ms; -100.042ms] or [-52.045%; -49.719%]

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

  • 🟥 execution_time [+11.217ms; +15.133ms] or [+5.616%; +7.576%]

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

  • 🟥 execution_time [+20.666ms; +26.959ms] or [+10.738%; +14.008%]

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

  • 🟩 execution_time [-19.407ms; -13.040ms] or [-9.019%; -6.060%]

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

  • 🟥 execution_time [+20.672ms; +20.976ms] or [+11.479%; +11.648%]
  • 🟩 throughput [+357.644op/s; +368.443op/s] or [+5.514%; +5.681%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟩 execution_time [-45.781ms; -39.462ms] or [-19.619%; -16.911%]
  • 🟩 throughput [+126.867op/s; +160.340op/s] or [+12.303%; +15.549%]

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

  • 🟩 execution_time [-1.736ms; -1.658ms] or [-44.736%; -42.705%]
  • 🟩 throughput [+195.111op/s; +205.444op/s] or [+75.716%; +79.726%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch net472

  • 🟥 throughput [-21777.717op/s; -20432.323op/s] or [-7.449%; -6.989%]

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

  • 🟥 throughput [-38689.984op/s; -27641.339op/s] or [-8.254%; -5.897%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net472

  • 🟥 throughput [-28231.813op/s; -27129.460op/s] or [-10.039%; -9.647%]

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

  • 🟥 throughput [-309.869op/s; -114.804op/s] or [-14.875%; -5.511%]

@dudikeleti dudikeleti force-pushed the dudik/el-fix-null-equality branch from e0ca6a7 to e33f17c Compare January 20, 2026 22:10
@dudikeleti dudikeleti enabled auto-merge (squash) January 20, 2026 23:34
@dudikeleti dudikeleti merged commit fd0f5fd into master Jan 20, 2026
152 of 154 checks passed
@dudikeleti dudikeleti deleted the dudik/el-fix-null-equality branch January 20, 2026 23:44
@github-actions github-actions bot added this to the vNext-v3 milestone Jan 20, 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