Skip to content

Conversation

@dudikeleti
Copy link
Contributor

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

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.

@dudikeleti dudikeleti requested a review from a team as a code owner December 20, 2025 13:58
@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
@dd-trace-dotnet-ci-bot
Copy link

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (7994) 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.68 ± (68.68 - 68.92) ms+0.5%✅⬆️
.NET Framework 4.8 - Bailout
duration72.04 ± (71.98 - 72.19) ms72.27 ± (72.22 - 72.43) ms+0.3%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1002.12 ± (1004.91 - 1011.87) ms1007.32 ± (1008.55 - 1015.02) ms+0.5%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms21.95 ± (21.93 - 21.97) ms21.88 ± (21.85 - 21.91) ms-0.3%
process.time_to_main_ms78.46 ± (78.35 - 78.58) ms78.90 ± (78.73 - 79.07) ms+0.6%✅⬆️
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.95 ± (21.93 - 21.97) ms21.87 ± (21.84 - 21.90) ms-0.4%
process.time_to_main_ms79.96 ± (79.89 - 80.04) ms79.93 ± (79.85 - 80.02) ms-0.0%
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) ms210.77 ± (209.28 - 212.26) ms+0.2%✅⬆️
process.time_to_main_ms472.04 ± (471.46 - 472.62) ms472.74 ± (472.21 - 473.27) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.10 ± (48.08 - 48.12) MB48.15 ± (48.13 - 48.17) MB+0.1%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.0%
.NET 6 - Baseline
process.internal_duration_ms20.65 ± (20.63 - 20.68) ms20.61 ± (20.59 - 20.64) ms-0.2%
process.time_to_main_ms68.09 ± (67.97 - 68.20) ms68.07 ± (67.96 - 68.17) ms-0.0%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.61 ± (10.61 - 10.61) MB10.64 ± (10.64 - 10.64) MB+0.3%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms20.61 ± (20.58 - 20.64) ms20.52 ± (20.50 - 20.54) ms-0.5%
process.time_to_main_ms68.94 ± (68.88 - 69.01) ms68.97 ± (68.92 - 69.03) ms+0.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.74 ± (10.73 - 10.74) MB10.69 ± (10.69 - 10.70) MB-0.4%
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) ms200.83 ± (199.76 - 201.91) ms+0.3%✅⬆️
process.time_to_main_ms437.61 ± (436.97 - 438.24) ms441.01 ± (440.48 - 441.53) ms+0.8%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.00 ± (47.92 - 48.08) MB48.40 ± (48.33 - 48.46) MB+0.8%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.3%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms18.82 ± (18.79 - 18.84) ms18.96 ± (18.93 - 18.99) ms+0.8%✅⬆️
process.time_to_main_ms66.98 ± (66.87 - 67.08) ms67.48 ± (67.36 - 67.59) ms+0.7%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.69 ± (7.68 - 7.70) MB7.67 ± (7.67 - 7.68) MB-0.2%
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms18.81 ± (18.79 - 18.82) ms18.87 ± (18.85 - 18.90) ms+0.3%✅⬆️
process.time_to_main_ms68.07 ± (68.01 - 68.13) ms68.42 ± (68.37 - 68.47) ms+0.5%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.73 ± (7.72 - 7.74) MB7.74 ± (7.73 - 7.75) MB+0.2%✅⬆️
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) ms179.49 ± (178.54 - 180.44) ms-0.4%
process.time_to_main_ms425.59 ± (424.81 - 426.37) ms424.38 ± (423.74 - 425.03) ms-0.3%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.31 ± (36.27 - 36.34) MB36.35 ± (36.32 - 36.38) MB+0.1%✅⬆️
runtime.dotnet.threads.count27 ± (27 - 27)27 ± (27 - 27)-0.2%

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration192.71 ± (193.01 - 193.77) ms193.66 ± (193.67 - 194.50) ms+0.5%✅⬆️
.NET Framework 4.8 - Bailout
duration196.49 ± (196.15 - 196.64) ms196.87 ± (196.57 - 197.07) ms+0.2%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1111.56 ± (1114.95 - 1123.79) ms1111.15 ± (1114.33 - 1122.73) ms-0.0%
.NET Core 3.1 - Baseline
process.internal_duration_ms187.49 ± (187.10 - 187.89) ms188.20 ± (187.80 - 188.60) ms+0.4%✅⬆️
process.time_to_main_ms80.17 ± (79.97 - 80.38) ms80.68 ± (80.46 - 80.89) ms+0.6%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.06 ± (16.04 - 16.09) MB16.09 ± (16.06 - 16.11) MB+0.1%✅⬆️
runtime.dotnet.threads.count20 ± (19 - 20)20 ± (20 - 20)+0.2%✅⬆️
.NET Core 3.1 - Bailout
process.internal_duration_ms186.68 ± (186.37 - 187.00) ms186.99 ± (186.72 - 187.27) ms+0.2%✅⬆️
process.time_to_main_ms81.54 ± (81.42 - 81.65) ms81.73 ± (81.61 - 81.85) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.16 ± (16.13 - 16.19) MB16.13 ± (16.10 - 16.16) MB-0.2%
runtime.dotnet.threads.count21 ± (21 - 21)21 ± (21 - 21)+0.2%✅⬆️
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms395.98 ± (393.57 - 398.40) ms399.89 ± (397.00 - 402.78) ms+1.0%✅⬆️
process.time_to_main_ms475.83 ± (475.22 - 476.43) ms472.56 ± (471.97 - 473.15) ms-0.7%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed58.48 ± (58.33 - 58.62) MB58.51 ± (58.37 - 58.65) MB+0.1%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)-0.1%
.NET 6 - Baseline
process.internal_duration_ms191.69 ± (191.34 - 192.03) ms191.98 ± (191.62 - 192.33) ms+0.2%✅⬆️
process.time_to_main_ms69.73 ± (69.57 - 69.90) ms70.14 ± (69.90 - 70.38) ms+0.6%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.04 ± (15.90 - 16.18) MB16.25 ± (16.15 - 16.34) MB+1.3%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 19)19 ± (18 - 19)+2.2%✅⬆️
.NET 6 - Bailout
process.internal_duration_ms190.64 ± (190.43 - 190.86) ms190.97 ± (190.75 - 191.19) ms+0.2%✅⬆️
process.time_to_main_ms70.36 ± (70.28 - 70.43) ms70.73 ± (70.61 - 70.85) ms+0.5%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.11 ± (15.97 - 16.26) MB16.20 ± (16.06 - 16.33) MB+0.5%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)-0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms411.54 ± (408.95 - 414.13) ms409.31 ± (406.97 - 411.65) ms-0.5%
process.time_to_main_ms443.81 ± (443.28 - 444.33) ms444.23 ± (443.74 - 444.72) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed59.01 ± (58.88 - 59.14) MB59.19 ± (59.06 - 59.33) MB+0.3%✅⬆️
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (30 - 30)-0.2%
.NET 8 - Baseline
process.internal_duration_ms189.64 ± (189.37 - 189.91) ms190.08 ± (189.74 - 190.41) ms+0.2%✅⬆️
process.time_to_main_ms69.26 ± (69.04 - 69.48) ms69.54 ± (69.37 - 69.70) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.70 ± (11.64 - 11.75) MB11.76 ± (11.72 - 11.79) MB+0.5%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)+2.0%✅⬆️
.NET 8 - Bailout
process.internal_duration_ms189.20 ± (188.95 - 189.45) ms190.03 ± (189.68 - 190.37) ms+0.4%✅⬆️
process.time_to_main_ms70.22 ± (70.12 - 70.32) ms70.50 ± (70.39 - 70.62) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.80 ± (11.75 - 11.84) MB11.80 ± (11.77 - 11.83) MB+0.0%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)+0.8%✅⬆️
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms362.33 ± (360.62 - 364.04) ms362.90 ± (361.41 - 364.39) ms+0.2%✅⬆️
process.time_to_main_ms426.00 ± (425.47 - 426.54) ms428.79 ± (428.24 - 429.33) ms+0.7%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed47.95 ± (47.92 - 47.98) MB47.93 ± (47.90 - 47.96) 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 (7994) - mean (69ms)  : 67, 70
    master - mean (69ms)  : 67, 70

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

    section CallTarget+Inlining+NGEN
    This PR (7994) - mean (1,012ms)  : 966, 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 (7994) - mean (106ms)  : 103, 110
    master - mean (106ms)  : 103, 108

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

    section CallTarget+Inlining+NGEN
    This PR (7994) - mean (712ms)  : 677, 747
    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 (7994) - mean (93ms)  : 92, 95
    master - mean (94ms)  : 92, 95

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

    section CallTarget+Inlining+NGEN
    This PR (7994) - mean (670ms)  : 643, 697
    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 (7994) - mean (93ms)  : 91, 95
    master - mean (92ms)  : 90, 94

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

    section CallTarget+Inlining+NGEN
    This PR (7994) - mean (631ms)  : 618, 645
    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 (7994) - mean (194ms)  : 190, 198
    master - mean (193ms)  : 189, 197

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

    section CallTarget+Inlining+NGEN
    This PR (7994) - mean (1,119ms)  : 1058, 1179
    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 (7994) - mean (277ms)  : 272, 282
    master - mean (276ms)  : 270, 282

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

    section CallTarget+Inlining+NGEN
    This PR (7994) - mean (909ms)  : 864, 954
    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 (7994) - mean (270ms)  : 265, 276
    master - mean (270ms)  : 265, 275

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

    section CallTarget+Inlining+NGEN
    This PR (7994) - mean (890ms)  : 839, 941
    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 (7994) - mean (269ms)  : 265, 274
    master - mean (268ms)  : 264, 273

    section Bailout
    This PR (7994) - mean (270ms)  : 266, 274
    master - mean (269ms)  : 266, 272

    section CallTarget+Inlining+NGEN
    This PR (7994) - mean (823ms)  : 804, 842
    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