-
Notifications
You must be signed in to change notification settings - Fork 143
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
Add CallTarget support for ValueTask
in .NET FX and < .NET Core 3.1
#6480
base: master
Are you sure you want to change the base?
Conversation
Datadog ReportBranch report: ✅ 0 Failed, 460294 Passed, 2839 Skipped, 19h 33m 23.78s Total Time |
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:
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 (6480) - mean (68ms) : 66, 71
. : milestone, 68,
master - mean (68ms) : 66, 71
. : milestone, 68,
section CallTarget+Inlining+NGEN
This PR (6480) - mean (977ms) : 944, 1011
. : milestone, 977,
master - mean (978ms) : 957, 1000
. : milestone, 978,
gantt
title Execution time (ms) FakeDbCommand (.NET Core 3.1)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (6480) - mean (107ms) : 105, 109
. : milestone, 107,
master - mean (107ms) : 104, 109
. : milestone, 107,
section CallTarget+Inlining+NGEN
This PR (6480) - mean (674ms) : 659, 688
. : milestone, 674,
master - mean (678ms) : 664, 693
. : milestone, 678,
gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (6480) - mean (91ms) : 89, 93
. : milestone, 91,
master - mean (90ms) : 89, 92
. : milestone, 90,
section CallTarget+Inlining+NGEN
This PR (6480) - mean (629ms) : 608, 650
. : milestone, 629,
master - mean (632ms) : 616, 649
. : milestone, 632,
gantt
title Execution time (ms) HttpMessageHandler (.NET Framework 4.6.2)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (6480) - mean (194ms) : 189, 199
. : milestone, 194,
master - mean (193ms) : 189, 198
. : milestone, 193,
section CallTarget+Inlining+NGEN
This PR (6480) - mean (1,102ms) : 1074, 1131
. : milestone, 1102,
master - mean (1,095ms) : 1068, 1122
. : milestone, 1095,
gantt
title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (6480) - mean (279ms) : 273, 284
. : milestone, 279,
master - mean (277ms) : 272, 282
. : milestone, 277,
section CallTarget+Inlining+NGEN
This PR (6480) - mean (871ms) : 831, 912
. : milestone, 871,
master - mean (870ms) : 840, 900
. : milestone, 870,
gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (6480) - mean (266ms) : 262, 270
. : milestone, 266,
master - mean (267ms) : 262, 271
. : milestone, 267,
section CallTarget+Inlining+NGEN
This PR (6480) - mean (845ms) : 817, 873
. : milestone, 845,
master - mean (850ms) : 816, 883
. : milestone, 850,
|
ffc922e
to
457a93f
Compare
Benchmarks Report for tracer 🐌Benchmarks for #6480 compared to master:
The following thresholds were used for comparing the benchmark speeds:
Allocation changes below 0.5% are ignored. Benchmark detailsBenchmarks.Trace.ActivityBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.AgentWriterBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.AspNetCoreBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.DbCommandBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.ElasticsearchBenchmark - Slower
|
Benchmark | diff/base | Base Median (ns) | Diff Median (ns) | Modality |
---|---|---|---|---|
Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync‑net6.0 | 1.139 | 1,225.37 | 1,395.46 |
Raw results
Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
---|---|---|---|---|---|---|---|---|---|
master | CallElasticsearch |
net6.0 | 1.23μs | 0.494ns | 1.91ns | 0.0136 | 0 | 0 | 976 B |
master | CallElasticsearch |
netcoreapp3.1 | 1.5μs | 2.82ns | 10.9ns | 0.0134 | 0 | 0 | 976 B |
master | CallElasticsearch |
net472 | 2.55μs | 1.48ns | 5.53ns | 0.157 | 0 | 0 | 995 B |
master | CallElasticsearchAsync |
net6.0 | 1.23μs | 0.454ns | 1.7ns | 0.0135 | 0 | 0 | 952 B |
master | CallElasticsearchAsync |
netcoreapp3.1 | 1.69μs | 1.01ns | 3.64ns | 0.0136 | 0 | 0 | 1.02 KB |
master | CallElasticsearchAsync |
net472 | 2.56μs | 2.59ns | 10ns | 0.167 | 0 | 0 | 1.05 KB |
#6480 | CallElasticsearch |
net6.0 | 1.18μs | 0.884ns | 3.31ns | 0.0137 | 0 | 0 | 976 B |
#6480 | CallElasticsearch |
netcoreapp3.1 | 1.57μs | 0.556ns | 2ns | 0.0133 | 0 | 0 | 976 B |
#6480 | CallElasticsearch |
net472 | 2.57μs | 0.742ns | 2.57ns | 0.157 | 0 | 0 | 995 B |
#6480 | CallElasticsearchAsync |
net6.0 | 1.4μs | 0.692ns | 2.49ns | 0.0133 | 0 | 0 | 952 B |
#6480 | CallElasticsearchAsync |
netcoreapp3.1 | 1.65μs | 1.66ns | 6.44ns | 0.014 | 0 | 0 | 1.02 KB |
#6480 | CallElasticsearchAsync |
net472 | 2.6μs | 2.86ns | 10.7ns | 0.166 | 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.37μs | 0.559ns | 2.09ns | 0.0137 | 0 | 0 | 952 B |
master | ExecuteAsync |
netcoreapp3.1 | 1.69μs | 1.13ns | 4.21ns | 0.0128 | 0 | 0 | 952 B |
master | ExecuteAsync |
net472 | 1.81μs | 0.455ns | 1.76ns | 0.145 | 0 | 0 | 915 B |
#6480 | ExecuteAsync |
net6.0 | 1.34μs | 0.785ns | 2.94ns | 0.0128 | 0 | 0 | 952 B |
#6480 | ExecuteAsync |
netcoreapp3.1 | 1.58μs | 0.714ns | 2.67ns | 0.0126 | 0 | 0 | 952 B |
#6480 | ExecuteAsync |
net472 | 1.74μs | 0.803ns | 3.11ns | 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.33μs | 1.38ns | 4.97ns | 0.0327 | 0 | 0 | 2.31 KB |
master | SendAsync |
netcoreapp3.1 | 5.43μs | 1.75ns | 6.54ns | 0.0381 | 0 | 0 | 2.85 KB |
master | SendAsync |
net472 | 7.36μs | 2.66ns | 9.94ns | 0.492 | 0 | 0 | 3.12 KB |
#6480 | SendAsync |
net6.0 | 4.36μs | 1.86ns | 7.19ns | 0.0328 | 0 | 0 | 2.31 KB |
#6480 | SendAsync |
netcoreapp3.1 | 5.27μs | 2.25ns | 8.7ns | 0.0395 | 0 | 0 | 2.85 KB |
#6480 | SendAsync |
net472 | 7.39μs | 1.7ns | 6.59ns | 0.495 | 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.5μs | 0.943ns | 3.53ns | 0.0233 | 0 | 0 | 1.64 KB |
master | EnrichedLog |
netcoreapp3.1 | 2.41μs | 1.75ns | 6.55ns | 0.0227 | 0 | 0 | 1.64 KB |
master | EnrichedLog |
net472 | 2.7μs | 1.41ns | 5.45ns | 0.249 | 0 | 0 | 1.57 KB |
#6480 | EnrichedLog |
net6.0 | 1.46μs | 1.07ns | 4ns | 0.0231 | 0 | 0 | 1.64 KB |
#6480 | EnrichedLog |
netcoreapp3.1 | 2.27μs | 1.75ns | 6.76ns | 0.0215 | 0 | 0 | 1.64 KB |
#6480 | EnrichedLog |
net472 | 2.72μs | 1.87ns | 6.99ns | 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 | 115μs | 131ns | 508ns | 0.058 | 0 | 0 | 4.28 KB |
master | EnrichedLog |
netcoreapp3.1 | 124μs | 200ns | 776ns | 0 | 0 | 0 | 4.28 KB |
master | EnrichedLog |
net472 | 150μs | 242ns | 937ns | 0.677 | 0.226 | 0 | 4.46 KB |
#6480 | EnrichedLog |
net6.0 | 117μs | 213ns | 827ns | 0 | 0 | 0 | 4.28 KB |
#6480 | EnrichedLog |
netcoreapp3.1 | 120μs | 278ns | 1.08μs | 0 | 0 | 0 | 4.28 KB |
#6480 | EnrichedLog |
net472 | 152μs | 141ns | 544ns | 0.681 | 0.227 | 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 | 2.98μs | 0.781ns | 3.03ns | 0.0298 | 0 | 0 | 2.2 KB |
master | EnrichedLog |
netcoreapp3.1 | 4.22μs | 1.5ns | 5.4ns | 0.0295 | 0 | 0 | 2.2 KB |
master | EnrichedLog |
net472 | 4.83μs | 1.05ns | 4.06ns | 0.319 | 0 | 0 | 2.02 KB |
#6480 | EnrichedLog |
net6.0 | 2.88μs | 1.44ns | 5.38ns | 0.0304 | 0 | 0 | 2.2 KB |
#6480 | EnrichedLog |
netcoreapp3.1 | 4.35μs | 1.05ns | 4.07ns | 0.0283 | 0 | 0 | 2.2 KB |
#6480 | EnrichedLog |
net472 | 4.85μs | 0.933ns | 3.61ns | 0.319 | 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.42μs | 0.335ns | 1.25ns | 0.0163 | 0 | 0 | 1.14 KB |
master | SendReceive |
netcoreapp3.1 | 1.85μs | 0.584ns | 2.18ns | 0.0155 | 0 | 0 | 1.14 KB |
master | SendReceive |
net472 | 2.02μs | 1.76ns | 6.83ns | 0.183 | 0 | 0 | 1.16 KB |
#6480 | SendReceive |
net6.0 | 1.31μs | 0.978ns | 3.79ns | 0.0158 | 0 | 0 | 1.14 KB |
#6480 | SendReceive |
netcoreapp3.1 | 1.73μs | 1.15ns | 4.46ns | 0.0155 | 0 | 0 | 1.14 KB |
#6480 | SendReceive |
net472 | 2.09μs | 1.65ns | 6.19ns | 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.74μs | 0.813ns | 3.15ns | 0.0233 | 0 | 0 | 1.6 KB |
master | EnrichedLog |
netcoreapp3.1 | 4.07μs | 2.35ns | 8.78ns | 0.0224 | 0 | 0 | 1.65 KB |
master | EnrichedLog |
net472 | 4.32μs | 3.1ns | 11.6ns | 0.322 | 0 | 0 | 2.04 KB |
#6480 | EnrichedLog |
net6.0 | 2.74μs | 3.9ns | 15.1ns | 0.0218 | 0 | 0 | 1.6 KB |
#6480 | EnrichedLog |
netcoreapp3.1 | 3.96μs | 1.7ns | 6.6ns | 0.0216 | 0 | 0 | 1.65 KB |
#6480 | EnrichedLog |
net472 | 4.46μs | 3.29ns | 12.8ns | 0.324 | 0 | 0 | 2.04 KB |
Benchmarks.Trace.SpanBenchmark - Slower ⚠️ Same allocations ✔️
Slower ⚠️ in #6480
Benchmark
diff/base
Base Median (ns)
Diff Median (ns)
Modality
Benchmarks.Trace.SpanBenchmark.StartFinishScope‑net6.0
1.161
480.44
557.77
Benchmark | diff/base | Base Median (ns) | Diff Median (ns) | Modality |
---|---|---|---|---|
Benchmarks.Trace.SpanBenchmark.StartFinishScope‑net6.0 | 1.161 | 480.44 | 557.77 |
Raw results
Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
---|---|---|---|---|---|---|---|---|---|
master | StartFinishSpan |
net6.0 | 394ns | 0.22ns | 0.852ns | 0.00808 | 0 | 0 | 576 B |
master | StartFinishSpan |
netcoreapp3.1 | 625ns | 0.695ns | 2.6ns | 0.00764 | 0 | 0 | 576 B |
master | StartFinishSpan |
net472 | 658ns | 0.454ns | 1.76ns | 0.0917 | 0 | 0 | 578 B |
master | StartFinishScope |
net6.0 | 481ns | 0.199ns | 0.769ns | 0.00982 | 0 | 0 | 696 B |
master | StartFinishScope |
netcoreapp3.1 | 729ns | 1.06ns | 4.11ns | 0.00949 | 0 | 0 | 696 B |
master | StartFinishScope |
net472 | 846ns | 0.376ns | 1.36ns | 0.104 | 0 | 0 | 658 B |
#6480 | StartFinishSpan |
net6.0 | 409ns | 0.732ns | 2.83ns | 0.00809 | 0 | 0 | 576 B |
#6480 | StartFinishSpan |
netcoreapp3.1 | 675ns | 0.376ns | 1.41ns | 0.00768 | 0 | 0 | 576 B |
#6480 | StartFinishSpan |
net472 | 691ns | 0.369ns | 1.43ns | 0.0917 | 0 | 0 | 578 B |
#6480 | StartFinishScope |
net6.0 | 558ns | 0.328ns | 1.23ns | 0.00981 | 0 | 0 | 696 B |
#6480 | StartFinishScope |
netcoreapp3.1 | 655ns | 0.598ns | 2.24ns | 0.00916 | 0 | 0 | 696 B |
#6480 | StartFinishScope |
net472 | 861ns | 0.499ns | 1.93ns | 0.104 | 0 | 0 | 658 B |
Benchmarks.Trace.TraceAnnotationsBenchmark - Same speed ✔️ Same allocations ✔️
Raw results
Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
---|---|---|---|---|---|---|---|---|---|
master | RunOnMethodBegin |
net6.0 | 640ns | 1.74ns | 6.75ns | 0.00959 | 0 | 0 | 696 B |
master | RunOnMethodBegin |
netcoreapp3.1 | 897ns | 1.04ns | 4.02ns | 0.00942 | 0 | 0 | 696 B |
master | RunOnMethodBegin |
net472 | 1.05μs | 0.815ns | 3.16ns | 0.104 | 0 | 0 | 658 B |
#6480 | RunOnMethodBegin |
net6.0 | 592ns | 0.286ns | 1.11ns | 0.00975 | 0 | 0 | 696 B |
#6480 | RunOnMethodBegin |
netcoreapp3.1 | 894ns | 0.663ns | 2.57ns | 0.0094 | 0 | 0 | 696 B |
#6480 | RunOnMethodBegin |
net472 | 1.15μs | 0.498ns | 1.93ns | 0.104 | 0 | 0 | 658 B |
457a93f
to
6c8dbe5
Compare
Throughput/Crank Report ⚡Throughput results for AspNetCoreSimpleController comparing the following branches/commits: Cases where throughput results for the PR are worse than latest master (5% drop or greater), results are shown in red. Note that these results are based on a single point-in-time result for each branch. For full results, see one of the many, many dashboards! gantt
title Throughput Linux x64 (Total requests)
dateFormat X
axisFormat %s
section Baseline
This PR (6480) (11.113M) : 0, 11112891
master (11.278M) : 0, 11278464
benchmarks/2.9.0 (11.144M) : 0, 11143547
section Automatic
This PR (6480) (7.431M) : 0, 7431434
master (7.310M) : 0, 7310284
benchmarks/2.9.0 (7.982M) : 0, 7981525
section Trace stats
master (7.466M) : 0, 7466025
section Manual
master (11.098M) : 0, 11098414
section Manual + Automatic
This PR (6480) (6.769M) : 0, 6769440
master (6.596M) : 0, 6596135
section DD_TRACE_ENABLED=0
master (10.177M) : 0, 10177094
gantt
title Throughput Linux arm64 (Total requests)
dateFormat X
axisFormat %s
section Baseline
This PR (6480) (9.563M) : 0, 9563388
master (9.615M) : 0, 9615070
benchmarks/2.9.0 (9.621M) : 0, 9621397
section Automatic
This PR (6480) (6.501M) : 0, 6500795
master (6.452M) : 0, 6452148
section Trace stats
master (6.369M) : 0, 6369273
section Manual
master (9.539M) : 0, 9539051
section Manual + Automatic
This PR (6480) (5.924M) : 0, 5924116
master (6.003M) : 0, 6003427
section DD_TRACE_ENABLED=0
master (8.846M) : 0, 8846180
gantt
title Throughput Windows x64 (Total requests)
dateFormat X
axisFormat %s
section Baseline
This PR (6480) (10.316M) : 0, 10316293
master (9.954M) : 0, 9954268
section Automatic
This PR (6480) (6.707M) : 0, 6706701
master (6.674M) : 0, 6674018
section Trace stats
master (7.283M) : 0, 7282769
section Manual
master (10.371M) : 0, 10370838
section Manual + Automatic
This PR (6480) (6.238M) : 0, 6237748
master (6.188M) : 0, 6187851
section DD_TRACE_ENABLED=0
master (9.569M) : 0, 9568617
|
Initially we wrote the Task integration in such a way to avoid declaring |
Summary of changes
Add support for correct
CallTarget
instrumentation of methods that returnValueTask
in < .NET Core 3.1 or .NET FrameworkReason for change
We already support instrumenting methods that returns
ValueTask
in .NET Core 3.1. However, in .NET Framework or .NET Standard 2.0, this support is provided by a package, and we currently don't support instrumenting these methods. Or rather, we just ignore theOnAsyncMethodEnd
in integrations in these cases.Implementation details
We already support
ValueTask
in more recent frameworks, and the support is very similar to ourTask
support. Unfortunately, in .NET FX we can't reference theValueTask
type itself.To work around this, we do the following:
ValueTask
orValueTask<T>
either by loading the type directly (.NET Core) or checking the type name (.NET Framework)ValueTask
to read theIsCompletedSuccessfully
value.ValueTask<T>
we duck typeResult
and read that directly too.Task
from it.Task()
for uncompletedValueTask
Task
integrationsValueTask
instead from the previous oneValueTask
require that we create a "fresh" one, we can't just "reuse" the one we got originally, because we've already retrieved the result/ awaited the inner taskActivator
/DynamicMethod
for thisWarning
The existing
ValueTask
/ValueTask<>
andTask
/Task<>
integrations are written quite differently, and I'm not entirely sure why 🤔 Given theContinuationAction()
methods for both these cases operate onTask
, I based on the newValueTask
integrations on theTask
integrations, but if anyone has reasons why it shouldn't be, I'm all ears!Test coverage
Task
andValueTask
tests to theCallTargetNativeTests
integration tests. Previously we were only testing a singleTask
example, and that was somewhat insufficientCallTargetNativeTests
to explicitly assert that theOnAsyncMethodEnd
methods are called forTask
/ValueTask
method integrations. As we provide both methods in our target integration, we were silently calling the wrong one for .NET FXValueTaskAsyncContinutationGenerator
unit tests on all TFMs, not just .NET Core 3.1ValueTaskHelper
for checking if a type is aValueTask
ValueTaskActivator
for creating aValueTask
from aTask
orTask<T>
Other details
Required for