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

HTTP over streams: use vendored Utf8Parser.TryParse() #6720

Merged
merged 1 commit into from
Mar 7, 2025

Conversation

lucaspimentel
Copy link
Member

@lucaspimentel lucaspimentel commented Feb 27, 2025

Summary of changes

We have a "vendored" copy of Utf8Parser available to use now, so use that instead of copying the code for Utf8Parser.TryParse() to use in older runtimes.

Reason for change

Reduce code duplication. Maintainability, etc, etc. First step towards a larger clean up of "vendored" runtime code.

Implementation details

  • When targeting .NET Core >= 3.1, use Utf8Parser from System.Buffers.Text (we were already doing this for .NET >= 6)
  • Otherwise, use Utf8Parser from Datadog.Trace.VendoredMicrosoftCode.System.Buffers.Text
  • remote the copy of Utf8Parser.TryParse() that is no longer used

Test coverage

No change in behavior. Existing tests should pass.

Other details

n/a

@github-actions github-actions bot added the area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) label Feb 27, 2025
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Feb 27, 2025

Datadog Report

Branch report: lpimentel/use-built-in-types-1
Commit report: e905c25
Test service: dd-trace-dotnet

✅ 0 Failed, 252570 Passed, 2397 Skipped, 19h 42m 17.06s Total Time

@andrewlock
Copy link
Member

andrewlock commented Feb 27, 2025

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 (6720) - mean (70ms)  : 64, 76
     .   : milestone, 70,
    master - mean (70ms)  : 66, 73
     .   : milestone, 70,

    section CallTarget+Inlining+NGEN
    This PR (6720) - mean (1,006ms)  : 981, 1031
     .   : milestone, 1006,
    master - mean (1,004ms)  : 982, 1026
     .   : milestone, 1004,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6720) - mean (104ms)  : 101, 106
     .   : milestone, 104,
    master - mean (102ms)  : 100, 105
     .   : milestone, 102,

    section CallTarget+Inlining+NGEN
    This PR (6720) - mean (691ms)  : 674, 709
     .   : milestone, 691,
    master - mean (688ms)  : 670, 706
     .   : milestone, 688,

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

    section CallTarget+Inlining+NGEN
    This PR (6720) - mean (644ms)  : 626, 662
     .   : milestone, 644,
    master - mean (644ms)  : 625, 662
     .   : milestone, 644,

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

    section CallTarget+Inlining+NGEN
    This PR (6720) - mean (1,112ms)  : 1089, 1134
     .   : milestone, 1112,
    master - mean (1,105ms)  : 1081, 1130
     .   : milestone, 1105,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6720) - mean (270ms)  : 267, 274
     .   : milestone, 270,
    master - mean (269ms)  : 266, 272
     .   : milestone, 269,

    section CallTarget+Inlining+NGEN
    This PR (6720) - mean (876ms)  : 851, 901
     .   : milestone, 876,
    master - mean (874ms)  : 842, 905
     .   : milestone, 874,

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

    section CallTarget+Inlining+NGEN
    This PR (6720) - mean (857ms)  : 824, 889
     .   : milestone, 857,
    master - mean (856ms)  : 827, 886
     .   : milestone, 856,

Loading

@lucaspimentel lucaspimentel changed the title use vendored Utf8Parser.TryParse() use vendored Utf8Parser.TryParse() Feb 27, 2025
@lucaspimentel lucaspimentel force-pushed the lpimentel/use-built-in-types-1 branch from 97ee6e6 to 08cda07 Compare February 27, 2025 16:29
@andrewlock
Copy link
Member

andrewlock commented Feb 27, 2025

Benchmarks Report for tracer 🐌

Benchmarks for #6720 compared to master:

  • 2 benchmarks are slower, with geometric mean 1.138
  • 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 8.55μs 49.2ns 399ns 0.0168 0.0084 0 5.61 KB
master StartStopWithChild netcoreapp3.1 10.6μs 57ns 317ns 0.0161 0.00536 0 5.8 KB
master StartStopWithChild net472 16.2μs 55.7ns 216ns 1.06 0.321 0.0962 6.21 KB
#6720 StartStopWithChild net6.0 8.57μs 48.8ns 460ns 0.017 0.00852 0 5.61 KB
#6720 StartStopWithChild netcoreapp3.1 10.7μs 62.8ns 605ns 0.0264 0.0105 0 5.8 KB
#6720 StartStopWithChild net472 16.2μs 46.9ns 182ns 1.04 0.297 0.104 6.21 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 545μs 481ns 1.73μs 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 647μs 277ns 1.04μs 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces net472 837μs 820ns 3.18μs 0.417 0 0 3.3 KB
#6720 WriteAndFlushEnrichedTraces net6.0 511μs 436ns 1.69μs 0 0 0 2.7 KB
#6720 WriteAndFlushEnrichedTraces netcoreapp3.1 663μs 428ns 1.54μs 0 0 0 2.7 KB
#6720 WriteAndFlushEnrichedTraces net472 860μs 776ns 2.91μs 0.428 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 134μs 224ns 867ns 0.2 0 0 14.47 KB
master SendRequest netcoreapp3.1 149μs 522ns 2.02μs 0.222 0 0 17.27 KB
master SendRequest net472 0.000677ns 0.000371ns 0.00139ns 0 0 0 0 b
#6720 SendRequest net6.0 131μs 334ns 1.29μs 0.132 0 0 14.47 KB
#6720 SendRequest netcoreapp3.1 146μs 378ns 1.47μs 0.218 0 0 17.28 KB
#6720 SendRequest net472 6.35E‑05ns 5.1E‑05ns 0.000198ns 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 564μs 3.1μs 18.6μs 0.561 0 0 41.52 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 688μs 3.91μs 28.2μs 0.349 0 0 41.65 KB
master WriteAndFlushEnrichedTraces net472 859μs 3.94μs 15.8μs 8.25 2.6 0.434 53.28 KB
#6720 WriteAndFlushEnrichedTraces net6.0 569μs 3.31μs 30.7μs 0.556 0 0 41.53 KB
#6720 WriteAndFlushEnrichedTraces netcoreapp3.1 706μs 3.96μs 25.3μs 0.329 0 0 41.67 KB
#6720 WriteAndFlushEnrichedTraces net472 874μs 4.36μs 20μs 8.3 2.62 0.437 53.26 KB
Benchmarks.Trace.DbCommandBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteNonQuery net6.0 1.32μs 1.56ns 6.04ns 0.0139 0 0 1.02 KB
master ExecuteNonQuery netcoreapp3.1 1.83μs 2.57ns 9.97ns 0.0135 0 0 1.02 KB
master ExecuteNonQuery net472 2μs 2.75ns 10.7ns 0.156 0.000988 0 987 B
#6720 ExecuteNonQuery net6.0 1.33μs 1.61ns 6.25ns 0.0139 0 0 1.02 KB
#6720 ExecuteNonQuery netcoreapp3.1 1.81μs 1.43ns 4.95ns 0.0135 0 0 1.02 KB
#6720 ExecuteNonQuery net472 2.08μs 4.15ns 16.1ns 0.156 0.00104 0 987 B
Benchmarks.Trace.ElasticsearchBenchmark - Slower ⚠️ Same allocations ✔️

Slower ⚠️ in #6720

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync‑net6.0 1.139 1,232.60 1,404.04

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master CallElasticsearch net6.0 1.19μs 0.604ns 2.18ns 0.0136 0 0 976 B
master CallElasticsearch netcoreapp3.1 1.55μs 1.37ns 5.29ns 0.0132 0 0 976 B
master CallElasticsearch net472 2.46μs 1.15ns 4.32ns 0.158 0 0 995 B
master CallElasticsearchAsync net6.0 1.23μs 0.855ns 3.31ns 0.013 0 0 952 B
master CallElasticsearchAsync netcoreapp3.1 1.63μs 0.777ns 2.91ns 0.0129 0 0 1.02 KB
master CallElasticsearchAsync net472 2.66μs 0.442ns 1.59ns 0.166 0 0 1.05 KB
#6720 CallElasticsearch net6.0 1.22μs 1.01ns 3.93ns 0.0136 0 0 976 B
#6720 CallElasticsearch netcoreapp3.1 1.62μs 0.853ns 3.31ns 0.013 0 0 976 B
#6720 CallElasticsearch net472 2.54μs 1.17ns 4.37ns 0.158 0 0 995 B
#6720 CallElasticsearchAsync net6.0 1.4μs 1.24ns 4.8ns 0.0135 0 0 952 B
#6720 CallElasticsearchAsync netcoreapp3.1 1.63μs 0.709ns 2.56ns 0.0133 0 0 1.02 KB
#6720 CallElasticsearchAsync net472 2.57μs 1.24ns 4.63ns 0.166 0 0 1.05 KB
Benchmarks.Trace.GraphQLBenchmark - Slower ⚠️ Same allocations ✔️

Slower ⚠️ in #6720

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync‑netcoreapp3.1 1.136 1,538.99 1,748.66

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteAsync net6.0 1.31μs 0.379ns 1.37ns 0.0134 0 0 952 B
master ExecuteAsync netcoreapp3.1 1.54μs 0.406ns 1.57ns 0.0123 0 0 952 B
master ExecuteAsync net472 1.82μs 0.663ns 2.48ns 0.145 0 0 915 B
#6720 ExecuteAsync net6.0 1.43μs 0.355ns 1.33ns 0.0133 0 0 952 B
#6720 ExecuteAsync netcoreapp3.1 1.75μs 1.41ns 5.09ns 0.0125 0 0 952 B
#6720 ExecuteAsync net472 1.88μs 0.678ns 2.44ns 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.52μs 2.28ns 8.83ns 0.0317 0 0 2.31 KB
master SendAsync netcoreapp3.1 5.33μs 2.32ns 8.69ns 0.0374 0 0 2.85 KB
master SendAsync net472 7.58μs 2.23ns 8.63ns 0.495 0 0 3.12 KB
#6720 SendAsync net6.0 4.39μs 1.48ns 5.55ns 0.0329 0 0 2.31 KB
#6720 SendAsync netcoreapp3.1 5.27μs 1.41ns 5.1ns 0.0395 0 0 2.85 KB
#6720 SendAsync net472 7.56μs 2.08ns 8.07ns 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.46μs 0.721ns 2.7ns 0.0226 0 0 1.64 KB
master EnrichedLog netcoreapp3.1 2.21μs 1.5ns 5.61ns 0.0221 0 0 1.64 KB
master EnrichedLog net472 2.57μs 0.925ns 3.58ns 0.249 0 0 1.57 KB
#6720 EnrichedLog net6.0 1.43μs 0.85ns 3.29ns 0.0229 0 0 1.64 KB
#6720 EnrichedLog netcoreapp3.1 2.26μs 1.47ns 5.29ns 0.0224 0 0 1.64 KB
#6720 EnrichedLog net472 2.49μs 0.747ns 2.89ns 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 113μs 125ns 485ns 0.0565 0 0 4.28 KB
master EnrichedLog netcoreapp3.1 117μs 269ns 1.04μs 0.058 0 0 4.28 KB
master EnrichedLog net472 149μs 119ns 459ns 0.67 0.223 0 4.46 KB
#6720 EnrichedLog net6.0 111μs 116ns 449ns 0.0553 0 0 4.28 KB
#6720 EnrichedLog netcoreapp3.1 117μs 233ns 903ns 0.0586 0 0 4.28 KB
#6720 EnrichedLog net472 147μs 124ns 466ns 0.661 0.22 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.07μs 0.605ns 2.18ns 0.0305 0 0 2.2 KB
master EnrichedLog netcoreapp3.1 4.24μs 1.06ns 3.95ns 0.0299 0 0 2.2 KB
master EnrichedLog net472 4.82μs 1.12ns 4.34ns 0.319 0 0 2.02 KB
#6720 EnrichedLog net6.0 3.04μs 1.21ns 4.51ns 0.0305 0 0 2.2 KB
#6720 EnrichedLog netcoreapp3.1 4.09μs 0.989ns 3.83ns 0.0285 0 0 2.2 KB
#6720 EnrichedLog net472 4.86μs 2.02ns 7.81ns 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.32μs 1.3ns 5.03ns 0.0161 0 0 1.14 KB
master SendReceive netcoreapp3.1 1.77μs 1.98ns 7.66ns 0.015 0 0 1.14 KB
master SendReceive net472 2.08μs 1.79ns 6.93ns 0.184 0 0 1.16 KB
#6720 SendReceive net6.0 1.37μs 0.959ns 3.71ns 0.0163 0 0 1.14 KB
#6720 SendReceive netcoreapp3.1 1.76μs 0.827ns 3.2ns 0.015 0 0 1.14 KB
#6720 SendReceive net472 2.14μs 0.625ns 2.34ns 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.72μs 0.995ns 3.86ns 0.0218 0 0 1.6 KB
master EnrichedLog netcoreapp3.1 3.91μs 1.19ns 4.46ns 0.0214 0 0 1.65 KB
master EnrichedLog net472 4.23μs 2.68ns 10ns 0.323 0 0 2.04 KB
#6720 EnrichedLog net6.0 2.83μs 1ns 3.75ns 0.0226 0 0 1.6 KB
#6720 EnrichedLog netcoreapp3.1 3.9μs 1.49ns 5.76ns 0.0214 0 0 1.65 KB
#6720 EnrichedLog net472 4.25μs 1.99ns 7.45ns 0.322 0 0 2.04 KB
Benchmarks.Trace.SpanBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartFinishSpan net6.0 409ns 0.0715ns 0.267ns 0.00811 0 0 576 B
master StartFinishSpan netcoreapp3.1 602ns 0.432ns 1.67ns 0.00785 0 0 576 B
master StartFinishSpan net472 659ns 0.167ns 0.626ns 0.0918 0 0 578 B
master StartFinishScope net6.0 522ns 0.215ns 0.803ns 0.00979 0 0 696 B
master StartFinishScope netcoreapp3.1 701ns 0.744ns 2.78ns 0.00936 0 0 696 B
master StartFinishScope net472 822ns 0.815ns 3.16ns 0.104 0 0 658 B
#6720 StartFinishSpan net6.0 412ns 0.153ns 0.591ns 0.00801 0 0 576 B
#6720 StartFinishSpan netcoreapp3.1 617ns 0.259ns 1ns 0.00773 0 0 576 B
#6720 StartFinishSpan net472 598ns 0.302ns 1.17ns 0.0918 0 0 578 B
#6720 StartFinishScope net6.0 498ns 0.115ns 0.444ns 0.0099 0 0 696 B
#6720 StartFinishScope netcoreapp3.1 735ns 1.48ns 5.72ns 0.00901 0 0 696 B
#6720 StartFinishScope net472 822ns 0.583ns 2.18ns 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 606ns 0.195ns 0.756ns 0.00974 0 0 696 B
master RunOnMethodBegin netcoreapp3.1 961ns 0.384ns 1.49ns 0.00932 0 0 696 B
master RunOnMethodBegin net472 1.06μs 0.562ns 2.1ns 0.104 0 0 658 B
#6720 RunOnMethodBegin net6.0 669ns 0.362ns 1.4ns 0.00999 0 0 696 B
#6720 RunOnMethodBegin netcoreapp3.1 979ns 0.475ns 1.84ns 0.00929 0 0 696 B
#6720 RunOnMethodBegin net472 1.02μs 0.306ns 1.15ns 0.104 0 0 658 B

@lucaspimentel lucaspimentel force-pushed the lpimentel/use-built-in-types-1 branch from 08cda07 to f6984b4 Compare March 5, 2025 19:50
@lucaspimentel lucaspimentel marked this pull request as ready for review March 7, 2025 00:45
@lucaspimentel lucaspimentel requested a review from a team as a code owner March 7, 2025 00:45
@lucaspimentel lucaspimentel force-pushed the lpimentel/use-built-in-types-1 branch from f6984b4 to e905c25 Compare March 7, 2025 15:31
Copy link
Collaborator

@bouwkast bouwkast left a comment

Choose a reason for hiding this comment

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

👍

@lucaspimentel lucaspimentel changed the title use vendored Utf8Parser.TryParse() HTTP over streams: use vendored Utf8Parser.TryParse() Mar 7, 2025
@lucaspimentel lucaspimentel merged commit 8b0b501 into master Mar 7, 2025
144 of 146 checks passed
@lucaspimentel lucaspimentel deleted the lpimentel/use-built-in-types-1 branch March 7, 2025 19:38
@github-actions github-actions bot added this to the vNext-v3 milestone Mar 7, 2025
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) type:refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants