Skip to content

[EL] DEBUG-4879 Support multiple expression compilations#7994

Merged
dudikeleti merged 3 commits intomasterfrom
dudik/el-support-multiple-compilations
Jan 21, 2026
Merged

[EL] DEBUG-4879 Support multiple expression compilations#7994
dudikeleti merged 3 commits intomasterfrom
dudik/el-support-multiple-compilations

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

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

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.40 ± (68.39 - 68.62) ms68.65 ± (68.59 - 68.81) ms+0.4%✅⬆️
.NET Framework 4.8 - Bailout
duration72.40 ± (72.33 - 72.55) ms72.58 ± (72.45 - 72.64) ms+0.2%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1005.21 ± (1012.27 - 1022.62) ms1004.07 ± (1006.24 - 1013.13) ms-0.1%
.NET Core 3.1 - Baseline
process.internal_duration_ms22.01 ± (21.97 - 22.04) ms21.97 ± (21.93 - 22.00) ms-0.2%
process.time_to_main_ms79.41 ± (79.23 - 79.59) ms79.32 ± (79.15 - 79.50) ms-0.1%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.92 ± (10.91 - 10.92) MB10.91 ± (10.91 - 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.92 - 21.98) ms21.92 ± (21.90 - 21.94) ms-0.1%
process.time_to_main_ms80.58 ± (80.49 - 80.67) ms80.22 ± (80.12 - 80.32) ms-0.4%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.96 ± (10.96 - 10.96) MB10.95 ± (10.94 - 10.95) MB-0.1%
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms252.96 ± (250.03 - 255.90) ms248.34 ± (244.77 - 251.92) ms-1.8%
process.time_to_main_ms470.67 ± (470.10 - 471.23) ms472.92 ± (472.30 - 473.54) ms+0.5%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.41 ± (48.39 - 48.44) MB48.45 ± (48.43 - 48.47) MB+0.1%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.0%
.NET 6 - Baseline
process.internal_duration_ms20.67 ± (20.64 - 20.70) ms20.75 ± (20.72 - 20.78) ms+0.4%✅⬆️
process.time_to_main_ms68.46 ± (68.35 - 68.58) ms68.68 ± (68.57 - 68.80) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.62 ± (10.62 - 10.62) MB10.63 ± (10.62 - 10.63) MB+0.0%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms20.60 ± (20.57 - 20.64) ms20.66 ± (20.63 - 20.68) ms+0.3%✅⬆️
process.time_to_main_ms69.44 ± (69.37 - 69.51) ms69.45 ± (69.39 - 69.50) ms+0.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.74 ± (10.73 - 10.74) MB10.73 ± (10.72 - 10.74) MB-0.0%
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms247.63 ± (245.52 - 249.74) ms247.06 ± (244.79 - 249.33) ms-0.2%
process.time_to_main_ms447.54 ± (446.98 - 448.10) ms450.77 ± (450.22 - 451.32) ms+0.7%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed49.17 ± (49.14 - 49.20) MB49.21 ± (49.17 - 49.24) MB+0.1%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.0%
.NET 8 - Baseline
process.internal_duration_ms18.86 ± (18.83 - 18.89) ms19.05 ± (19.02 - 19.07) ms+1.0%✅⬆️
process.time_to_main_ms67.71 ± (67.59 - 67.83) ms67.97 ± (67.85 - 68.08) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.67 ± (7.66 - 7.68) MB7.69 ± (7.68 - 7.70) MB+0.3%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms18.97 ± (18.93 - 19.00) ms19.11 ± (19.08 - 19.14) ms+0.8%✅⬆️
process.time_to_main_ms68.88 ± (68.81 - 68.95) ms69.07 ± (69.00 - 69.15) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.72 ± (7.72 - 7.73) MB7.73 ± (7.72 - 7.74) MB+0.1%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms178.21 ± (177.35 - 179.07) ms179.81 ± (178.84 - 180.77) ms+0.9%✅⬆️
process.time_to_main_ms431.45 ± (430.56 - 432.33) ms432.28 ± (431.52 - 433.04) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.55 ± (36.52 - 36.59) MB36.62 ± (36.59 - 36.65) MB+0.2%✅⬆️
runtime.dotnet.threads.count26 ± (26 - 26)27 ± (27 - 27)+0.6%✅⬆️

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration194.29 ± (194.37 - 195.30) ms194.13 ± (194.03 - 194.81) ms-0.1%
.NET Framework 4.8 - Bailout
duration197.40 ± (197.36 - 197.97) ms197.67 ± (197.49 - 198.02) ms+0.1%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1125.21 ± (1125.58 - 1133.41) ms1122.77 ± (1126.21 - 1135.19) ms-0.2%
.NET Core 3.1 - Baseline
process.internal_duration_ms188.60 ± (188.25 - 188.94) ms188.51 ± (188.08 - 188.94) ms-0.0%
process.time_to_main_ms81.14 ± (80.91 - 81.37) ms81.30 ± (81.09 - 81.51) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.12 ± (16.09 - 16.15) MB16.19 ± (16.16 - 16.22) MB+0.4%✅⬆️
runtime.dotnet.threads.count20 ± (19 - 20)20 ± (20 - 20)+0.2%✅⬆️
.NET Core 3.1 - Bailout
process.internal_duration_ms188.31 ± (187.94 - 188.68) ms188.12 ± (187.77 - 188.47) ms-0.1%
process.time_to_main_ms82.91 ± (82.74 - 83.08) ms82.93 ± (82.75 - 83.10) ms+0.0%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.14 ± (16.11 - 16.17) MB16.18 ± (16.15 - 16.21) MB+0.2%✅⬆️
runtime.dotnet.threads.count21 ± (20 - 21)21 ± (21 - 21)+0.9%✅⬆️
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms429.32 ± (426.05 - 432.59) ms428.67 ± (425.68 - 431.66) ms-0.2%
process.time_to_main_ms475.09 ± (474.44 - 475.74) ms476.09 ± (475.44 - 476.73) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed58.70 ± (58.59 - 58.80) MB58.90 ± (58.80 - 59.00) MB+0.3%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 30)29 ± (29 - 29)-0.1%
.NET 6 - Baseline
process.internal_duration_ms193.49 ± (193.04 - 193.93) ms192.54 ± (192.19 - 192.89) ms-0.5%
process.time_to_main_ms71.09 ± (70.92 - 71.25) ms70.18 ± (69.99 - 70.37) ms-1.3%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.12 ± (15.99 - 16.25) MB16.19 ± (16.04 - 16.33) MB+0.4%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)18 ± (18 - 18)-3.8%
.NET 6 - Bailout
process.internal_duration_ms192.41 ± (192.06 - 192.75) ms191.55 ± (191.25 - 191.84) ms-0.4%
process.time_to_main_ms71.85 ± (71.68 - 72.02) ms71.47 ± (71.30 - 71.64) ms-0.5%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.28 ± (16.18 - 16.38) MB16.37 ± (16.27 - 16.46) MB+0.5%✅⬆️
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)-0.2%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms446.95 ± (443.90 - 450.00) ms448.28 ± (445.22 - 451.33) ms+0.3%✅⬆️
process.time_to_main_ms453.84 ± (453.20 - 454.47) ms452.86 ± (452.26 - 453.46) ms-0.2%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed58.86 ± (58.74 - 58.99) MB58.78 ± (58.65 - 58.91) MB-0.1%
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)+0.0%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms190.88 ± (190.53 - 191.22) ms191.23 ± (190.83 - 191.62) ms+0.2%✅⬆️
process.time_to_main_ms70.35 ± (70.16 - 70.54) ms70.41 ± (70.16 - 70.66) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.78 ± (11.75 - 11.81) MB11.71 ± (11.69 - 11.74) MB-0.5%
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)-0.3%
.NET 8 - Bailout
process.internal_duration_ms190.34 ± (189.99 - 190.68) ms190.37 ± (190.08 - 190.65) ms+0.0%✅⬆️
process.time_to_main_ms71.27 ± (71.12 - 71.41) ms71.08 ± (70.96 - 71.21) ms-0.3%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.88 ± (11.84 - 11.91) MB11.80 ± (11.77 - 11.83) MB-0.6%
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)-0.4%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms367.68 ± (366.20 - 369.15) ms368.24 ± (366.72 - 369.75) ms+0.2%✅⬆️
process.time_to_main_ms437.12 ± (436.43 - 437.82) ms439.19 ± (438.59 - 439.80) ms+0.5%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed48.22 ± (48.17 - 48.26) MB48.22 ± (48.19 - 48.26) MB+0.0%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 29)29 ± (29 - 29)+0.8%✅⬆️
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 (73ms)  : 72, 73
    master - mean (72ms)  : 71, 74

    section CallTarget+Inlining+NGEN
    This PR (7994) - mean (1,010ms)  : 961, 1059
    master - mean (1,017ms)  : 941, 1094

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 (107ms)  : 104, 110
    master - mean (107ms)  : 104, 109

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

    section CallTarget+Inlining+NGEN
    This PR (7994) - mean (750ms)  : 689, 812
    master - mean (749ms)  : 707, 791

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

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

    section CallTarget+Inlining+NGEN
    This PR (7994) - mean (722ms)  : 663, 781
    master - mean (721ms)  : 684, 759

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)  : 90, 97
    master - mean (93ms)  : 91, 95

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

    section CallTarget+Inlining+NGEN
    This PR (7994) - mean (640ms)  : 623, 656
    master - mean (637ms)  : 626, 647

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 (195ms)  : 188, 201

    section Bailout
    This PR (7994) - mean (198ms)  : 195, 200
    master - mean (198ms)  : 195, 201

    section CallTarget+Inlining+NGEN
    This PR (7994) - mean (1,131ms)  : 1067, 1195
    master - mean (1,129ms)  : 1074, 1185

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 (278ms)  : 271, 286
    master - mean (279ms)  : 273, 284

    section Bailout
    This PR (7994) - mean (280ms)  : 275, 285
    master - mean (280ms)  : 275, 284

    section CallTarget+Inlining+NGEN
    This PR (7994) - mean (938ms)  : 901, 975
    master - mean (938ms)  : 894, 981

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7994) - mean (271ms)  : 266, 276
    master - mean (273ms)  : 267, 278

    section Bailout
    This PR (7994) - mean (271ms)  : 267, 276
    master - mean (273ms)  : 266, 279

    section CallTarget+Inlining+NGEN
    This PR (7994) - mean (933ms)  : 890, 976
    master - mean (930ms)  : 873, 986

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

    section Bailout
    This PR (7994) - mean (271ms)  : 267, 275
    master - mean (271ms)  : 267, 276

    section CallTarget+Inlining+NGEN
    This PR (7994) - mean (838ms)  : 817, 860
    master - mean (836ms)  : 818, 854

Loading

@pr-commenter
Copy link

pr-commenter bot commented Jan 7, 2026

Benchmarks

Benchmark execution time: 2026-01-21 19:09:30

Comparing candidate commit 005d3eb in PR branch dudik/el-support-multiple-compilations with baseline commit ff591c6 in branch master.

Found 11 performance improvements and 9 performance regressions! Performance is the same for 159 metrics, 13 unstable metrics.

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

  • 🟩 execution_time [-102.245ms; -100.269ms] or [-50.763%; -49.782%]

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

  • 🟥 execution_time [+14.046ms; +19.819ms] or [+7.086%; +9.999%]

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

  • 🟥 execution_time [+11.158ms; +16.489ms] or [+5.689%; +8.406%]

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

  • 🟥 execution_time [+12.338ms; +16.005ms] or [+5.852%; +7.592%]

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

  • 🟥 execution_time [+20.086ms; +26.305ms] or [+10.234%; +13.402%]

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

  • 🟩 execution_time [-12.151ms; -10.247ms] or [-5.974%; -5.038%]

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

  • 🟩 execution_time [-101.477ms; -95.014ms] or [-51.831%; -48.530%]

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

  • 🟩 execution_time [-24.644ms; -21.033ms] or [-12.253%; -10.458%]

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

  • 🟩 execution_time [-69.478µs; -66.909µs] or [-6.454%; -6.215%]
  • 🟩 throughput [+61.586op/s; +64.059op/s] or [+6.630%; +6.896%]

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

  • 🟥 execution_time [+161.899µs; +169.381µs] or [+8.016%; +8.387%]
  • 🟥 throughput [-38.410op/s; -36.658op/s] or [-7.757%; -7.403%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net472

  • 🟩 throughput [+29816.946op/s; +31335.363op/s] or [+11.330%; +11.907%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net6.0

  • 🟩 execution_time [-16.291ms; -11.169ms] or [-7.712%; -5.287%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync netcoreapp3.1

  • 🟥 throughput [-44142.463op/s; -34750.293op/s] or [-9.644%; -7.592%]

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

  • 🟥 execution_time [+44.781ms; +46.493ms] or [+28.894%; +29.999%]

scenario:Benchmarks.Trace.RedisBenchmark.SendReceive netcoreapp3.1

  • 🟩 execution_time [-19.187ms; -13.451ms] or [-9.019%; -6.323%]
  • 🟩 throughput [+41456.638op/s; +52509.924op/s] or [+11.596%; +14.688%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net6.0

  • 🟩 execution_time [-108.656ms; -107.958ms] or [-54.462%; -54.112%]

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

  • 🟥 execution_time [+89.841ms; +92.054ms] or [+81.658%; +83.669%]

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 few comments around allocation and multithreading

// CRITICAL: Always use Value.GetType() for runtime type. If Value is null,
// we use the declared Type, but this can cause cache collisions when different
// runtime types share the same declared type (e.g., all inherit from Object).
var thisRuntimeType = invocationTarget.Value?.GetType();
Copy link
Contributor

Choose a reason for hiding this comment

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

invocationTarget can be null?

Copy link
Contributor Author

@dudikeleti dudikeleti Jan 9, 2026

Choose a reason for hiding this comment

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

static methods

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean, could we end up with NRE if we dereference invocationTarget.X throughout this method?


if (members != null && members.Length > 0)
{
var types = new Type?[members.Length];
Copy link
Contributor

Choose a reason for hiding this comment

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

can we minimize this allocation by reusing from a type pool? I'm worried we incur additional short-live allocation that might result in GC pressure if the method executes lots of time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem that we can't pool them if we want to use them as a long lived cache key, I made a few changes to the implementation to reduce allocations in most cases

Copy link
Contributor

@GreenMatan GreenMatan Jan 13, 2026

Choose a reason for hiding this comment

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

The creation of ExpressionCacheKey (and the Type array in it) is done every time we try to evaluate an expression - in other words, whenever the probe executes. Keeping it in memory for long is true only for the ExpressionCacheKey that ends up being saved in the dictionary. We could think about an approach that takes the array from the pool for lookup, and materialize it as heap allocated array only when the key doesn't exist (first time we encounter the specific type combination) while all subsequent executions will take & return the array from the pool. My concern is that we may induce GC pressure for short lived arrays

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out that I didn’t push my last commit. ExpressionCacheKey no longer exists.

Comment on lines +27 to +30
private readonly ConcurrentDictionary<ExpressionCacheKey, CompiledExpression<string>[]?> _compiledTemplatesByType = new();
private readonly ConcurrentDictionary<ExpressionCacheKey, CompiledExpression<bool>?> _compiledConditionByType = new();
private readonly ConcurrentDictionary<ExpressionCacheKey, CompiledExpression<double>?> _compiledMetricByType = new();
private readonly ConcurrentDictionary<ExpressionCacheKey, KeyValuePair<CompiledExpression<bool>, KeyValuePair<string?, CompiledExpression<string>[]>[]>[]?> _compiledDecorationsByType = new();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we improve this slow path of inquiring a ConcurrentDictionary, perhaps by using a Reader/Writer (slim) lock or other lock free approach?
We touch them in hot paths

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made a few changes to the implementation to reduce dictionary access, but overall I don’t think it’s worth it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's take it offline

@dudikeleti dudikeleti force-pushed the dudik/el-support-multiple-compilations branch from f9a9774 to 37c5583 Compare January 15, 2026 10:14
Replace 4 per-feature ConcurrentDictionary caches with a single bucketed cache keyed by (thisType, returnType, memberCount)
Avoid per-evaluation allocations/hashing by matching member runtime types inside the bucket
Ensure single compilation per type-combination with per-entry compile gating
Add monomorphic fast-path in bucket (_last) and reduce allocations on misses
Expose MethodScopeMembers.MemberCount to avoid scanning pooled member arrays
Lazy-init span-decoration result list
@dudikeleti dudikeleti force-pushed the dudik/el-support-multiple-compilations branch from ad2ab06 to 005d3eb Compare January 21, 2026 18:26
@dudikeleti dudikeleti requested a review from a team as a code owner January 21, 2026 18:26
@dudikeleti dudikeleti merged commit 6d5bc20 into master Jan 21, 2026
154 checks passed
@dudikeleti dudikeleti deleted the dudik/el-support-multiple-compilations branch January 21, 2026 20:10
@github-actions github-actions bot added this to the vNext-v3 milestone Jan 21, 2026
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