-
Notifications
You must be signed in to change notification settings - Fork 146
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
Perf optimization for protobuf instrumentation #6694
Conversation
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 (6694) - mean (69ms) : 66, 72
. : milestone, 69,
master - mean (69ms) : 66, 72
. : milestone, 69,
section CallTarget+Inlining+NGEN
This PR (6694) - mean (1,002ms) : 980, 1024
. : milestone, 1002,
master - mean (998ms) : 973, 1022
. : milestone, 998,
gantt
title Execution time (ms) FakeDbCommand (.NET Core 3.1)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (6694) - mean (103ms) : 101, 105
. : milestone, 103,
master - mean (102ms) : 99, 105
. : milestone, 102,
section CallTarget+Inlining+NGEN
This PR (6694) - mean (674ms) : 659, 690
. : milestone, 674,
master - mean (678ms) : 659, 697
. : milestone, 678,
gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (6694) - mean (89ms) : 87, 91
. : milestone, 89,
master - mean (89ms) : 87, 90
. : milestone, 89,
section CallTarget+Inlining+NGEN
This PR (6694) - mean (627ms) : 607, 647
. : milestone, 627,
master - mean (631ms) : 615, 647
. : milestone, 631,
gantt
title Execution time (ms) HttpMessageHandler (.NET Framework 4.6.2)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (6694) - mean (191ms) : 188, 195
. : milestone, 191,
master - mean (191ms) : 187, 196
. : milestone, 191,
section CallTarget+Inlining+NGEN
This PR (6694) - mean (1,110ms) : 1086, 1135
. : milestone, 1110,
master - mean (1,114ms) : 1079, 1149
. : milestone, 1114,
gantt
title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (6694) - mean (272ms) : 267, 277
. : milestone, 272,
master - mean (271ms) : 267, 276
. : milestone, 271,
section CallTarget+Inlining+NGEN
This PR (6694) - mean (865ms) : 838, 892
. : milestone, 865,
master - mean (869ms) : 838, 901
. : milestone, 869,
gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (6694) - mean (263ms) : 258, 269
. : milestone, 263,
master - mean (262ms) : 258, 266
. : milestone, 262,
section CallTarget+Inlining+NGEN
This PR (6694) - mean (848ms) : 810, 886
. : milestone, 848,
master - mean (848ms) : 816, 880
. : milestone, 848,
|
Benchmarks Report for tracer 🐌Benchmarks for #6694 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 - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.GraphQLBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.HttpClientBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.ILoggerBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.Log4netBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.NLogBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.RedisBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.SerilogBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.SpanBenchmark - Slower
|
Benchmark | diff/base | Base Median (ns) | Diff Median (ns) | Modality |
---|---|---|---|---|
Benchmarks.Trace.SpanBenchmark.StartFinishSpan‑net472 | 1.149 | 591.85 | 680.08 |
Raw results
Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
---|---|---|---|---|---|---|---|---|---|
master | StartFinishSpan |
net6.0 | 447ns | 0.887ns | 3.43ns | 0.00806 | 0 | 0 | 576 B |
master | StartFinishSpan |
netcoreapp3.1 | 600ns | 0.831ns | 3ns | 0.00782 | 0 | 0 | 576 B |
master | StartFinishSpan |
net472 | 590ns | 1.96ns | 7.33ns | 0.0915 | 0 | 0 | 578 B |
master | StartFinishScope |
net6.0 | 482ns | 0.943ns | 3.53ns | 0.0097 | 0 | 0 | 696 B |
master | StartFinishScope |
netcoreapp3.1 | 717ns | 1.98ns | 7.68ns | 0.00962 | 0 | 0 | 696 B |
master | StartFinishScope |
net472 | 886ns | 1.84ns | 7.12ns | 0.105 | 0 | 0 | 658 B |
#6694 | StartFinishSpan |
net6.0 | 465ns | 0.633ns | 2.28ns | 0.00806 | 0 | 0 | 576 B |
#6694 | StartFinishSpan |
netcoreapp3.1 | 565ns | 0.597ns | 2.23ns | 0.0077 | 0 | 0 | 576 B |
#6694 | StartFinishSpan |
net472 | 679ns | 0.809ns | 3.03ns | 0.0916 | 0 | 0 | 578 B |
#6694 | StartFinishScope |
net6.0 | 482ns | 0.83ns | 3.11ns | 0.00977 | 0 | 0 | 696 B |
#6694 | StartFinishScope |
netcoreapp3.1 | 752ns | 0.856ns | 3.2ns | 0.00929 | 0 | 0 | 696 B |
#6694 | StartFinishScope |
net472 | 860ns | 1.69ns | 6.56ns | 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 | 679ns | 0.696ns | 2.69ns | 0.00986 | 0 | 0 | 696 B |
master | RunOnMethodBegin |
netcoreapp3.1 | 882ns | 0.557ns | 2.01ns | 0.0092 | 0 | 0 | 696 B |
master | RunOnMethodBegin |
net472 | 1.09μs | 1.9ns | 7.36ns | 0.104 | 0 | 0 | 658 B |
#6694 | RunOnMethodBegin |
net6.0 | 683ns | 0.775ns | 3ns | 0.00979 | 0 | 0 | 696 B |
#6694 | RunOnMethodBegin |
netcoreapp3.1 | 926ns | 1.81ns | 7.02ns | 0.00924 | 0 | 0 | 696 B |
#6694 | RunOnMethodBegin |
net472 | 1μs | 1.84ns | 7.12ns | 0.104 | 0 | 0 | 658 B |
tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Protobuf/Helper.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if this is what @tonyredondo recommends 😅
Co-authored-by: Lucas Pimentel <[email protected]>
3ee76fd
to
345fb91
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
// For performance reasons, we want to do the actual instrumentation work with a Duck constraint, | ||
// but to be able to disable the instrumentation we need the raw type | ||
// so we use 2 different methods to have access to both when we need it. | ||
// Note: Disabling OnMethodBegin means the OnMethodEnd will not be called afterward. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting thanks!
Summary of changes
Stop relying on the proto source file to know if we're dealing with an internal protobuf message.
Instead, we check the type at the very beginning, and disable the instrumentation for that type if we detect it's a google type.
This means we can also get rid of all the dark magic we had around making sure we can access the descriptor, because we now know we'll only do it for regular messages.
Reason for change
it's better perf
Implementation details
I use an other
OnMethodXxx
method to be able to access the raw type, I explained it in the comments.See this thread for more.
Test coverage
added a path in the integration tests that checks that
Other details