Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ducktype instance type check #6373

Merged
merged 1 commit into from
Nov 28, 2024
Merged

Ducktype instance type check #6373

merged 1 commit into from
Nov 28, 2024

Conversation

tonyredondo
Copy link
Member

Summary of changes

This PR adds a check to avoid creating a proxy if the instance is already of type T or target type.

Reason for change

This should avoid any misusage of the ducktype library while trying to duckcast something that doesn't need casting.

@tonyredondo tonyredondo requested a review from a team as a code owner November 28, 2024 16:57
@github-actions github-actions bot added the area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) label Nov 28, 2024
@datadog-ddstaging
Copy link

datadog-ddstaging bot commented Nov 28, 2024

Datadog Report

Branch report: tony/ducktype-cast-check
Commit report: f05ab9d
Test service: dd-trace-dotnet

✅ 0 Failed, 451316 Passed, 2716 Skipped, 19h 9m 8.68s Total Time

@andrewlock
Copy link
Member

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing the following branches/commits:

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 shown 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).

gantt
    title Execution time (ms) FakeDbCommand (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6373) - mean (69ms)  : 66, 71
     .   : milestone, 69,
    master - mean (69ms)  : 66, 72
     .   : milestone, 69,

    section CallTarget+Inlining+NGEN
    This PR (6373) - mean (976ms)  : 952, 1001
     .   : milestone, 976,
    master - mean (981ms)  : 961, 1002
     .   : milestone, 981,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6373) - mean (108ms)  : 106, 111
     .   : milestone, 108,
    master - mean (108ms)  : 106, 109
     .   : milestone, 108,

    section CallTarget+Inlining+NGEN
    This PR (6373) - mean (684ms)  : 668, 700
     .   : milestone, 684,
    master - mean (680ms)  : 664, 697
     .   : milestone, 680,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6373) - mean (91ms)  : 89, 93
     .   : milestone, 91,
    master - mean (91ms)  : 90, 93
     .   : milestone, 91,

    section CallTarget+Inlining+NGEN
    This PR (6373) - mean (626ms)  : 611, 642
     .   : milestone, 626,
    master - mean (632ms)  : 619, 645
     .   : milestone, 632,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6373) - mean (190ms)  : 186, 195
     .   : milestone, 190,
    master - mean (191ms)  : 186, 195
     .   : milestone, 191,

    section CallTarget+Inlining+NGEN
    This PR (6373) - mean (1,093ms)  : 1070, 1116
     .   : milestone, 1093,
    master - mean (1,089ms)  : 1059, 1119
     .   : milestone, 1089,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6373) - mean (276ms)  : 272, 281
     .   : milestone, 276,
    master - mean (275ms)  : 271, 278
     .   : milestone, 275,

    section CallTarget+Inlining+NGEN
    This PR (6373) - mean (869ms)  : 846, 892
     .   : milestone, 869,
    master - mean (869ms)  : 837, 901
     .   : milestone, 869,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6373) - mean (265ms)  : 261, 269
     .   : milestone, 265,
    master - mean (265ms)  : 261, 270
     .   : milestone, 265,

    section CallTarget+Inlining+NGEN
    This PR (6373) - mean (845ms)  : 818, 873
     .   : milestone, 845,
    master - mean (853ms)  : 824, 881
     .   : milestone, 853,

Loading

@andrewlock
Copy link
Member

Benchmarks Report for tracer 🐌

Benchmarks for #6373 compared to master:

  • 2 benchmarks are faster, with geometric mean 1.165
  • 2 benchmarks are slower, with geometric mean 1.149
  • All benchmarks have the same allocations

The following thresholds were used for comparing the benchmark speeds:

  • Mann–Whitney U test with statistical test for significance of 5%
  • Only results indicating a difference greater than 10% and 0.3 ns are considered.

Allocation changes below 0.5% are ignored.

Benchmark details

Benchmarks.Trace.ActivityBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartStopWithChild net6.0 7.95μs 43ns 228ns 0.0238 0.00794 0 5.61 KB
master StartStopWithChild netcoreapp3.1 9.96μs 54.6ns 345ns 0.0202 0.0101 0 5.81 KB
master StartStopWithChild net472 16.2μs 49.5ns 192ns 1.04 0.305 0.0964 6.21 KB
#6373 StartStopWithChild net6.0 7.86μs 43.9ns 270ns 0.0157 0.00786 0 5.61 KB
#6373 StartStopWithChild netcoreapp3.1 10.1μs 55.2ns 326ns 0.0197 0.00985 0 5.8 KB
#6373 StartStopWithChild net472 16.2μs 46.4ns 180ns 1.04 0.297 0.0861 6.22 KB
Benchmarks.Trace.AgentWriterBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 489μs 519ns 2.01μs 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 660μs 300ns 1.12μs 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces net472 856μs 435ns 1.68μs 0.428 0 0 3.3 KB
#6373 WriteAndFlushEnrichedTraces net6.0 485μs 335ns 1.3μs 0 0 0 2.7 KB
#6373 WriteAndFlushEnrichedTraces netcoreapp3.1 658μs 550ns 2.13μs 0 0 0 2.7 KB
#6373 WriteAndFlushEnrichedTraces net472 839μs 831ns 3.22μs 0.417 0 0 3.3 KB
Benchmarks.Trace.AspNetCoreBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendRequest net6.0 149μs 905ns 9.01μs 0.14 0 0 14.47 KB
master SendRequest netcoreapp3.1 170μs 1.01μs 9.72μs 0.16 0 0 17.27 KB
master SendRequest net472 0.000648ns 0.000333ns 0.00129ns 0 0 0 0 b
#6373 SendRequest net6.0 148μs 847ns 7.04μs 0.151 0 0 14.47 KB
#6373 SendRequest netcoreapp3.1 166μs 964ns 7.89μs 0.165 0 0 17.27 KB
#6373 SendRequest net472 0.00253ns 0.000741ns 0.00287ns 0 0 0 0 b
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 573μs 3.21μs 20.8μs 0.563 0 0 41.56 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 687μs 3.4μs 14.4μs 0.331 0 0 41.85 KB
master WriteAndFlushEnrichedTraces net472 866μs 4.24μs 18.9μs 8.45 2.53 0.422 53.33 KB
#6373 WriteAndFlushEnrichedTraces net6.0 581μs 2.58μs 9.3μs 0.563 0 0 41.7 KB
#6373 WriteAndFlushEnrichedTraces netcoreapp3.1 713μs 3.64μs 17.5μs 0.349 0 0 41.75 KB
#6373 WriteAndFlushEnrichedTraces net472 863μs 3.93μs 15.2μs 8.33 2.5 0.417 53.27 KB
Benchmarks.Trace.DbCommandBenchmark - Faster 🎉 Same allocations ✔️

Faster 🎉 in #6373

Benchmark base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.DbCommandBenchmark.ExecuteNonQuery‑net6.0 1.179 1,378.36 1,169.28

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteNonQuery net6.0 1.38μs 1.62ns 6.27ns 0.014 0 0 1.02 KB
master ExecuteNonQuery netcoreapp3.1 1.75μs 1.28ns 4.94ns 0.0141 0 0 1.02 KB
master ExecuteNonQuery net472 2.06μs 1.74ns 6.52ns 0.157 0.00103 0 987 B
#6373 ExecuteNonQuery net6.0 1.17μs 1.16ns 4.35ns 0.014 0 0 1.02 KB
#6373 ExecuteNonQuery netcoreapp3.1 1.79μs 1.73ns 6.48ns 0.0134 0 0 1.02 KB
#6373 ExecuteNonQuery net472 2.07μs 2.57ns 9.95ns 0.157 0.00103 0 987 B
Benchmarks.Trace.ElasticsearchBenchmark - Slower ⚠️ Same allocations ✔️

Slower ⚠️ in #6373

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch‑net6.0 1.175 1,070.28 1,257.55

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master CallElasticsearch net6.0 1.07μs 0.383ns 1.48ns 0.0139 0 0 976 B
master CallElasticsearch netcoreapp3.1 1.53μs 3.8ns 14.7ns 0.0127 0 0 976 B
master CallElasticsearch net472 2.53μs 1.78ns 6.91ns 0.158 0 0 995 B
master CallElasticsearchAsync net6.0 1.35μs 0.994ns 3.85ns 0.0129 0 0 952 B
master CallElasticsearchAsync netcoreapp3.1 1.62μs 0.928ns 3.47ns 0.0139 0 0 1.02 KB
master CallElasticsearchAsync net472 2.57μs 1.16ns 4.5ns 0.166 0 0 1.05 KB
#6373 CallElasticsearch net6.0 1.26μs 1.41ns 5.44ns 0.0139 0 0 976 B
#6373 CallElasticsearch netcoreapp3.1 1.58μs 0.633ns 2.37ns 0.0127 0 0 976 B
#6373 CallElasticsearch net472 2.59μs 1.4ns 5.43ns 0.158 0 0 995 B
#6373 CallElasticsearchAsync net6.0 1.39μs 0.711ns 2.66ns 0.0132 0 0 952 B
#6373 CallElasticsearchAsync netcoreapp3.1 1.6μs 0.794ns 2.97ns 0.0135 0 0 1.02 KB
#6373 CallElasticsearchAsync net472 2.61μs 0.525ns 1.89ns 0.167 0 0 1.05 KB
Benchmarks.Trace.GraphQLBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteAsync net6.0 1.36μs 0.59ns 2.28ns 0.0129 0 0 952 B
master ExecuteAsync netcoreapp3.1 1.71μs 1.26ns 4.73ns 0.0128 0 0 952 B
master ExecuteAsync net472 1.8μs 0.991ns 3.84ns 0.145 0 0 915 B
#6373 ExecuteAsync net6.0 1.28μs 1.31ns 4.91ns 0.0134 0 0 952 B
#6373 ExecuteAsync netcoreapp3.1 1.72μs 0.586ns 2.19ns 0.0129 0 0 952 B
#6373 ExecuteAsync net472 1.78μs 0.831ns 2.99ns 0.145 0 0 915 B
Benchmarks.Trace.HttpClientBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendAsync net6.0 4.39μs 0.787ns 2.84ns 0.0329 0 0 2.31 KB
master SendAsync netcoreapp3.1 5.3μs 1.78ns 6.65ns 0.0372 0 0 2.85 KB
master SendAsync net472 7.32μs 1.84ns 7.12ns 0.496 0 0 3.12 KB
#6373 SendAsync net6.0 4.39μs 4.08ns 15.3ns 0.0309 0 0 2.31 KB
#6373 SendAsync netcoreapp3.1 5.23μs 2.16ns 8.36ns 0.0392 0 0 2.85 KB
#6373 SendAsync net472 7.43μs 1.89ns 7.33ns 0.493 0 0 3.12 KB
Benchmarks.Trace.ILoggerBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 1.44μs 0.902ns 3.25ns 0.0232 0 0 1.64 KB
master EnrichedLog netcoreapp3.1 2.2μs 1.08ns 4.02ns 0.0222 0 0 1.64 KB
master EnrichedLog net472 2.57μs 0.955ns 3.57ns 0.249 0 0 1.57 KB
#6373 EnrichedLog net6.0 1.46μs 1.12ns 4.2ns 0.0227 0 0 1.64 KB
#6373 EnrichedLog netcoreapp3.1 2.27μs 1.27ns 4.39ns 0.0217 0 0 1.64 KB
#6373 EnrichedLog net472 2.52μs 0.985ns 3.69ns 0.249 0 0 1.57 KB
Benchmarks.Trace.Log4netBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 119μs 167ns 648ns 0 0 0 4.28 KB
master EnrichedLog netcoreapp3.1 124μs 80.7ns 313ns 0 0 0 4.28 KB
master EnrichedLog net472 152μs 118ns 424ns 0.681 0.227 0 4.46 KB
#6373 EnrichedLog net6.0 119μs 186ns 719ns 0.0601 0 0 4.28 KB
#6373 EnrichedLog netcoreapp3.1 125μs 194ns 752ns 0 0 0 4.28 KB
#6373 EnrichedLog net472 153μs 108ns 418ns 0.683 0.228 0 4.46 KB
Benchmarks.Trace.NLogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 3.14μs 0.853ns 3.19ns 0.0299 0 0 2.2 KB
master EnrichedLog netcoreapp3.1 4.24μs 1.61ns 6.25ns 0.03 0 0 2.2 KB
master EnrichedLog net472 4.86μs 1.96ns 7.59ns 0.319 0 0 2.02 KB
#6373 EnrichedLog net6.0 3.08μs 1.39ns 5.37ns 0.0294 0 0 2.2 KB
#6373 EnrichedLog netcoreapp3.1 4.08μs 4.17ns 15.6ns 0.0305 0 0 2.2 KB
#6373 EnrichedLog net472 4.85μs 1.18ns 4.57ns 0.32 0 0 2.02 KB
Benchmarks.Trace.RedisBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendReceive net6.0 1.36μs 0.625ns 2.16ns 0.0164 0 0 1.14 KB
master SendReceive netcoreapp3.1 1.68μs 1.22ns 4.24ns 0.015 0 0 1.14 KB
master SendReceive net472 2.05μs 0.976ns 3.52ns 0.183 0 0 1.16 KB
#6373 SendReceive net6.0 1.35μs 0.694ns 2.69ns 0.0162 0 0 1.14 KB
#6373 SendReceive netcoreapp3.1 1.77μs 1.29ns 4.98ns 0.0159 0 0 1.14 KB
#6373 SendReceive net472 2.18μs 1.94ns 7.5ns 0.183 0 0 1.16 KB
Benchmarks.Trace.SerilogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 2.75μs 0.938ns 3.51ns 0.0219 0 0 1.6 KB
master EnrichedLog netcoreapp3.1 3.95μs 1.67ns 6.48ns 0.0217 0 0 1.65 KB
master EnrichedLog net472 4.41μs 2.38ns 9.21ns 0.324 0 0 2.04 KB
#6373 EnrichedLog net6.0 2.83μs 1.01ns 3.9ns 0.0227 0 0 1.6 KB
#6373 EnrichedLog netcoreapp3.1 3.96μs 1.66ns 6.42ns 0.0218 0 0 1.65 KB
#6373 EnrichedLog net472 4.38μs 1.53ns 5.91ns 0.322 0 0 2.04 KB
Benchmarks.Trace.SpanBenchmark - Faster 🎉 Same allocations ✔️

Faster 🎉 in #6373

Benchmark base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.SpanBenchmark.StartFinishScope‑netcoreapp3.1 1.152 776.12 673.93

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartFinishSpan net6.0 395ns 0.512ns 1.84ns 0.00814 0 0 576 B
master StartFinishSpan netcoreapp3.1 556ns 2.07ns 8.01ns 0.00789 0 0 576 B
master StartFinishSpan net472 724ns 2.09ns 8.08ns 0.0915 0 0 578 B
master StartFinishScope net6.0 540ns 0.911ns 3.53ns 0.00984 0 0 696 B
master StartFinishScope netcoreapp3.1 775ns 1.25ns 4.85ns 0.00926 0 0 696 B
master StartFinishScope net472 934ns 1.22ns 4.73ns 0.104 0 0 658 B
#6373 StartFinishSpan net6.0 401ns 0.761ns 2.95ns 0.00812 0 0 576 B
#6373 StartFinishSpan netcoreapp3.1 601ns 0.956ns 3.7ns 0.00784 0 0 576 B
#6373 StartFinishSpan net472 678ns 1.2ns 4.65ns 0.0915 0 0 578 B
#6373 StartFinishScope net6.0 494ns 0.735ns 2.85ns 0.00976 0 0 696 B
#6373 StartFinishScope netcoreapp3.1 672ns 1.35ns 5.24ns 0.00937 0 0 696 B
#6373 StartFinishScope net472 891ns 1.68ns 6.49ns 0.104 0 0 658 B
Benchmarks.Trace.TraceAnnotationsBenchmark - Slower ⚠️ Same allocations ✔️

Slower ⚠️ in #6373

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin‑net6.0 1.123 576.21 647.28

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master RunOnMethodBegin net6.0 576ns 0.608ns 2.35ns 0.00977 0 0 696 B
master RunOnMethodBegin netcoreapp3.1 913ns 1.52ns 5.9ns 0.00932 0 0 696 B
master RunOnMethodBegin net472 1.1μs 1.9ns 7.37ns 0.104 0 0 658 B
#6373 RunOnMethodBegin net6.0 646ns 0.9ns 3.49ns 0.00971 0 0 696 B
#6373 RunOnMethodBegin netcoreapp3.1 846ns 1.34ns 5.17ns 0.00933 0 0 696 B
#6373 RunOnMethodBegin net472 1.1μs 2.14ns 8.28ns 0.104 0 0 658 B

@tonyredondo tonyredondo merged commit 7f5fb56 into master Nov 28, 2024
75 of 77 checks passed
@tonyredondo tonyredondo deleted the tony/ducktype-cast-check branch November 28, 2024 18:47
@github-actions github-actions bot added this to the vNext-v3 milestone Nov 28, 2024
veerbia pushed a commit that referenced this pull request Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) identified-by:telemetry type:reliability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants