Skip to content

[EL] DEBUG-4880 Align probe expression compilation with runtime types#7992

Merged
dudikeleti merged 2 commits intomasterfrom
dudik/el-fix-runtime-vs-compiletime-types
Jan 7, 2026
Merged

[EL] DEBUG-4880 Align probe expression compilation with runtime types#7992
dudikeleti merged 2 commits intomasterfrom
dudik/el-fix-runtime-vs-compiletime-types

Conversation

@dudikeleti
Copy link
Contributor

@dudikeleti dudikeleti commented Dec 20, 2025

Summary of changes

Align probe expression compilation with runtime types for this and args/locals to prevent type-mismatch runtime failures and keep expression-cache behavior consistent.

Reason for change

Expression compilation previously relied on declared types (ScopeMember.Type) for this and for args/locals. In practice, the expression cache key is based on runtime types, and values can differ from their declared types (e.g., declared Int32 but actual value Int64, or declared base type but runtime derived type). This could lead to cached expressions being compiled with one set of types but executed with another, causing runtime InvalidCastException during lambda execution.

Implementation details

  • For args/locals:
    • Create variables using Value.GetType() (when available) and fall back to the declared type otherwise.
    • Use the same runtime type in the Expression.Convert when reading ScopeMember.Value.
  • For this:
    • Resolve thisType once at the entry point (ParseExpression) preferring runtime type (InvocationTarget.Value?.GetType()), then pass it down via thisTypeOverride.
    • This ensures the same this type is used consistently throughout parsing/compilation.

Test coverage

Snapshot Exploration Test

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:17
@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
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@datadog-datadog-prod-us1

This comment has been minimized.

@pr-commenter
Copy link

pr-commenter bot commented Dec 20, 2025

Benchmarks

Benchmark execution time: 2026-01-06 11:32:04

Comparing candidate commit 4354a65 in PR branch dudik/el-fix-runtime-vs-compiletime-types with baseline commit f0a17cd in branch master.

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

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

  • 🟩 execution_time [-19.869ms; -14.462ms] or [-9.151%; -6.661%]

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

  • 🟥 execution_time [+15.402ms; +21.522ms] or [+7.859%; +10.982%]

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

  • 🟥 execution_time [+12.742ms; +18.757ms] or [+6.423%; +9.455%]

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

  • 🟥 execution_time [+42.253ms; +43.422ms] or [+45.390%; +46.645%]

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

  • 🟥 execution_time [+43.263ms; +47.221ms] or [+24.726%; +26.988%]

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

  • 🟩 execution_time [-13.124ms; -9.069ms] or [-9.114%; -6.298%]
  • 🟩 throughput [+99.330op/s; +142.503op/s] or [+6.875%; +9.863%]

scenario:Benchmarks.Trace.DbCommandBenchmark.ExecuteNonQuery net472

  • 🟥 throughput [-27248.565op/s; -26355.519op/s] or [-7.452%; -7.208%]

scenario:Benchmarks.Trace.HttpClientBenchmark.SendAsync netcoreapp3.1

  • 🟩 execution_time [-102.168ms; -99.772ms] or [-51.463%; -50.256%]
  • 🟩 throughput [+10194.668op/s; +12038.863op/s] or [+8.851%; +10.452%]

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

  • 🟩 throughput [+26002.464op/s; +36055.574op/s] or [+7.387%; +10.243%]

scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog netcoreapp3.1

  • 🟩 execution_time [-16.019ms; -11.704ms] or [-7.640%; -5.582%]

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

  • 🟩 throughput [+217.727op/s; +381.185op/s] or [+11.646%; +20.389%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog netcoreapp3.1

  • 🟩 execution_time [-30.473ms; -29.013ms] or [-15.192%; -14.464%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog netcoreapp3.1

  • 🟥 execution_time [+97.300ms; +100.026ms] or [+95.028%; +97.690%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope netcoreapp3.1

  • 🟩 execution_time [-16.166ms; -12.362ms] or [-7.604%; -5.815%]

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

  • 🟥 execution_time [+12.382ms; +17.682ms] or [+6.192%; +8.842%]

@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 (7992) 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.28 ± (68.29 - 68.50) ms68.39 ± (68.42 - 68.63) ms+0.2%✅⬆️
.NET Framework 4.8 - Bailout
duration71.99 ± (71.89 - 72.11) ms72.22 ± (72.22 - 72.42) ms+0.3%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1003.84 ± (1004.86 - 1010.51) ms1004.21 ± (1006.93 - 1013.37) ms+0.0%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms21.98 ± (21.94 - 22.01) ms21.99 ± (21.96 - 22.02) ms+0.0%✅⬆️
process.time_to_main_ms78.73 ± (78.59 - 78.86) ms78.61 ± (78.46 - 78.76) ms-0.2%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.91 ± (10.91 - 10.92) MB10.90 ± (10.89 - 10.90) MB-0.1%
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms21.96 ± (21.94 - 21.98) ms21.91 ± (21.89 - 21.92) ms-0.2%
process.time_to_main_ms79.88 ± (79.77 - 79.98) ms79.79 ± (79.72 - 79.87) ms-0.1%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.95 ± (10.94 - 10.95) 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_ms233.06 ± (228.71 - 237.41) ms239.08 ± (235.06 - 243.09) ms+2.6%✅⬆️
process.time_to_main_ms471.10 ± (470.60 - 471.59) ms472.30 ± (471.80 - 472.79) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.19 ± (48.17 - 48.21) MB48.20 ± (48.18 - 48.22) MB+0.0%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.9%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms20.63 ± (20.61 - 20.66) ms20.57 ± (20.54 - 20.60) ms-0.3%
process.time_to_main_ms67.93 ± (67.80 - 68.06) ms67.99 ± (67.89 - 68.08) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.62 ± (10.61 - 10.62) MB10.63 ± (10.63 - 10.63) MB+0.1%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms20.53 ± (20.51 - 20.55) ms20.60 ± (20.57 - 20.63) ms+0.4%✅⬆️
process.time_to_main_ms68.89 ± (68.83 - 68.96) ms69.08 ± (69.04 - 69.11) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.71 ± (10.70 - 10.72) MB10.74 ± (10.73 - 10.74) MB+0.2%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms247.40 ± (245.65 - 249.16) ms245.91 ± (243.50 - 248.32) ms-0.6%
process.time_to_main_ms441.81 ± (441.35 - 442.26) ms441.79 ± (441.32 - 442.27) ms-0.0%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.71 ± (48.67 - 48.74) MB48.62 ± (48.59 - 48.66) MB-0.2%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.1%
.NET 8 - Baseline
process.internal_duration_ms18.81 ± (18.79 - 18.84) ms18.84 ± (18.82 - 18.87) ms+0.2%✅⬆️
process.time_to_main_ms67.03 ± (66.91 - 67.15) ms67.21 ± (67.10 - 67.31) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.68 ± (7.67 - 7.69) MB7.68 ± (7.67 - 7.69) MB-0.1%
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms18.80 ± (18.78 - 18.83) ms18.83 ± (18.80 - 18.86) ms+0.1%✅⬆️
process.time_to_main_ms67.95 ± (67.90 - 68.01) ms68.01 ± (67.97 - 68.06) ms+0.1%✅⬆️
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_ms178.04 ± (177.08 - 179.01) ms178.75 ± (177.92 - 179.58) ms+0.4%✅⬆️
process.time_to_main_ms426.52 ± (425.87 - 427.16) ms426.54 ± (425.88 - 427.20) ms+0.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.30 ± (36.27 - 36.32) MB36.30 ± (36.27 - 36.33) 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
duration192.80 ± (193.00 - 193.91) ms197.78 ± (197.42 - 198.36) ms+2.6%✅⬆️
.NET Framework 4.8 - Bailout
duration196.55 ± (196.49 - 197.00) ms200.50 ± (200.25 - 201.21) ms+2.0%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1107.89 ± (1108.72 - 1115.98) ms1123.19 ± (1122.68 - 1130.92) ms+1.4%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms187.49 ± (187.10 - 187.87) ms187.73 ± (187.49 - 187.98) ms+0.1%✅⬆️
process.time_to_main_ms80.44 ± (80.27 - 80.62) ms80.63 ± (80.47 - 80.79) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.08 ± (16.05 - 16.10) MB16.11 ± (16.08 - 16.13) MB+0.2%✅⬆️
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)-0.3%
.NET Core 3.1 - Bailout
process.internal_duration_ms187.02 ± (186.66 - 187.38) ms187.20 ± (186.89 - 187.50) ms+0.1%✅⬆️
process.time_to_main_ms81.74 ± (81.58 - 81.90) ms81.99 ± (81.86 - 82.12) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.12 ± (16.09 - 16.14) MB16.18 ± (16.15 - 16.20) MB+0.4%✅⬆️
runtime.dotnet.threads.count21 ± (21 - 21)21 ± (21 - 21)-0.1%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms416.42 ± (413.10 - 419.73) ms416.30 ± (412.97 - 419.64) ms-0.0%
process.time_to_main_ms472.26 ± (471.66 - 472.86) ms472.95 ± (472.37 - 473.53) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed58.84 ± (58.73 - 58.94) MB58.88 ± (58.77 - 59.00) MB+0.1%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 30)30 ± (29 - 30)+0.1%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms191.63 ± (191.31 - 191.95) ms192.63 ± (192.28 - 192.98) ms+0.5%✅⬆️
process.time_to_main_ms69.75 ± (69.59 - 69.90) ms70.25 ± (70.07 - 70.43) ms+0.7%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.18 ± (16.05 - 16.30) MB15.94 ± (15.80 - 16.09) MB-1.4%
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (18 - 19)-0.8%
.NET 6 - Bailout
process.internal_duration_ms191.53 ± (191.16 - 191.89) ms190.98 ± (190.71 - 191.25) ms-0.3%
process.time_to_main_ms70.87 ± (70.76 - 70.98) ms70.91 ± (70.82 - 71.00) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.24 ± (16.11 - 16.37) MB16.36 ± (16.27 - 16.46) MB+0.8%✅⬆️
runtime.dotnet.threads.count20 ± (19 - 20)20 ± (19 - 20)-0.5%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms452.01 ± (449.54 - 454.47) ms452.83 ± (450.51 - 455.16) ms+0.2%✅⬆️
process.time_to_main_ms445.65 ± (445.15 - 446.16) ms444.72 ± (444.32 - 445.12) ms-0.2%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed58.32 ± (58.19 - 58.44) MB58.33 ± (58.21 - 58.45) MB+0.0%✅⬆️
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (29 - 30)-0.1%
.NET 8 - Baseline
process.internal_duration_ms190.47 ± (190.13 - 190.81) ms190.02 ± (189.74 - 190.29) ms-0.2%
process.time_to_main_ms69.40 ± (69.24 - 69.57) ms69.50 ± (69.29 - 69.71) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.74 ± (11.71 - 11.77) MB11.80 ± (11.77 - 11.83) MB+0.5%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)+0.1%✅⬆️
.NET 8 - Bailout
process.internal_duration_ms189.73 ± (189.48 - 189.98) ms189.62 ± (189.28 - 189.95) ms-0.1%
process.time_to_main_ms70.38 ± (70.27 - 70.48) ms70.54 ± (70.43 - 70.64) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.78 ± (11.74 - 11.81) MB11.85 ± (11.82 - 11.89) MB+0.6%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)+0.5%✅⬆️
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms368.03 ± (366.64 - 369.41) ms365.54 ± (363.92 - 367.16) ms-0.7%
process.time_to_main_ms429.86 ± (429.27 - 430.45) ms429.26 ± (428.65 - 429.87) ms-0.1%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed48.00 ± (47.98 - 48.03) MB48.00 ± (47.97 - 48.03) MB-0.0%
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)-0.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 (7992) - mean (69ms)  : 67, 70
    master - mean (68ms)  : 67, 70

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

    section CallTarget+Inlining+NGEN
    This PR (7992) - mean (1,010ms)  : 963, 1057
    master - mean (1,008ms)  : 968, 1048

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

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

    section CallTarget+Inlining+NGEN
    This PR (7992) - mean (736ms)  : 680, 791
    master - mean (731ms)  : 669, 793

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

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

    section CallTarget+Inlining+NGEN
    This PR (7992) - mean (712ms)  : 672, 751
    master - mean (713ms)  : 682, 744

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

    section Bailout
    This PR (7992) - mean (93ms)  : 92, 93
    master - mean (93ms)  : 92, 94

    section CallTarget+Inlining+NGEN
    This PR (7992) - mean (634ms)  : 618, 649
    master - mean (630ms)  : 618, 643

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

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

    section CallTarget+Inlining+NGEN
    This PR (7992) - mean (1,127ms)  : 1067, 1186
    master - mean (1,112ms)  : 1061, 1164

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 (7992) - mean (277ms)  : 273, 281
    master - mean (277ms)  : 272, 282

    section Bailout
    This PR (7992) - mean (277ms)  : 273, 281
    master - mean (277ms)  : 273, 282

    section CallTarget+Inlining+NGEN
    This PR (7992) - mean (918ms)  : 863, 974
    master - mean (918ms)  : 871, 966

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

    section Bailout
    This PR (7992) - mean (270ms)  : 266, 273
    master - mean (270ms)  : 266, 274

    section CallTarget+Inlining+NGEN
    This PR (7992) - mean (925ms)  : 885, 965
    master - mean (926ms)  : 889, 963

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

    section Bailout
    This PR (7992) - mean (269ms)  : 266, 273
    master - mean (270ms)  : 266, 273

    section CallTarget+Inlining+NGEN
    This PR (7992) - mean (824ms)  : 803, 846
    master - mean (829ms)  : 799, 860

Loading

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-fix-runtime-vs-compiletime-types branch from 7274bda to 4354a65 Compare January 6, 2026 10:33
@dudikeleti dudikeleti merged commit 5d1df24 into master Jan 7, 2026
154 checks passed
@dudikeleti dudikeleti deleted the dudik/el-fix-runtime-vs-compiletime-types branch January 7, 2026 14:54
@github-actions github-actions bot added this to the vNext-v3 milestone Jan 7, 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.

2 participants