Skip to content

Update vendored System.Runtime.CompilerServices.Unsafe#8469

Merged
andrewlock merged 2 commits intomasterfrom
andrew/update-vendors-7
Apr 23, 2026
Merged

Update vendored System.Runtime.CompilerServices.Unsafe#8469
andrewlock merged 2 commits intomasterfrom
andrew/update-vendors-7

Conversation

@andrewlock
Copy link
Copy Markdown
Member

Summary of changes

  • Create re-usable vendoring process for System.Runtime.CompilerServices.Unsafe
  • Update the vendored code (it's actually unchanged)

Reason for change

We want to be able to update vendored code as required. For the vendored System.Runtime.CompilerServices.Unsafe package, the source code is written directly as IL, and compiled using Ilasm.exe. So this PR introduces a simple "IL to C#" converter that converts that file to its C# equivalent, using the same InlineIL.Fody approach that we currently have.

The final result produces a file that is virtually identical to the existing one (which is good!). The only difference I made was to add the original IL line as a comment next to the Fody equivalent.

This also shows that the code has not actually changed (and it's unlikely it will tbh), so this just means we have a repeatable self-contained approach to regenerate this in the repo as required.

Implementation details

Told 🤖 to make the IL to C# converter, and it did 😄 I've given the code it generated a once-over to look for anything terrible, but the key thing is that the output is sane, and that's visibly basically unchanged, so I think it's fine.

Test coverage

@dudikeleti already wrote some extensive tests for the Unsafe implementation back when he originally ported it, which verifies that we can compile the methods, call them, and that the generated IL is identical to the "real" versions 🎉

Other details

https://datadoghq.atlassian.net/browse/APMLP-1207

Part of a stack updating our vendored system code

@andrewlock andrewlock requested review from a team as code owners April 16, 2026 12:45
@andrewlock andrewlock added area:vendors Code from other vendors AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos labels Apr 16, 2026
Comment on lines -46 to -48
<!-- https://www.nuget.org/packages/System.Private.CoreLib/1.0.0 -->
<PackageReference Include="System.Private.CoreLib" Version="1.0.0" />

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This should be in the previous commit, but meh 😅

@andrewlock andrewlock force-pushed the andrew/update-vendors-4 branch from bdf65ae to ef58938 Compare April 16, 2026 13:16
@andrewlock andrewlock requested review from a team as code owners April 16, 2026 13:16
@andrewlock andrewlock force-pushed the andrew/update-vendors-7 branch from 0ec03d2 to 3af08ab Compare April 16, 2026 13:16
@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented Apr 16, 2026

Benchmarks

Benchmark execution time: 2026-04-23 10:32:28

Comparing candidate commit 112589a in PR branch andrew/update-vendors-7 with baseline commit 59dbf09 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 27 metrics, 0 unstable metrics, 60 known flaky benchmarks, 27 flaky benchmarks without significant changes.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net6.0

  • 🟩 throughput [+7197.485op/s; +9437.241op/s] or [+6.050%; +7.932%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟥 execution_time [+308.162ms; +310.249ms] or [+152.921%; +153.956%]

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

  • 🟥 execution_time [+380.094ms; +383.300ms] or [+300.297%; +302.831%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1

  • 🟥 execution_time [+397.613ms; +398.968ms] or [+351.872%; +353.072%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody net472

  • 🟥 allocated_mem [+1.308KB; +1.308KB] or [+27.529%; +27.541%]

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

  • 🟥 allocated_mem [+471 bytes; +472 bytes] or [+9.977%; +9.987%]
  • 🟩 execution_time [-16.256ms; -12.057ms] or [-7.592%; -5.631%]

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

  • 🟥 allocated_mem [+1.272KB; +1.272KB] or [+27.502%; +27.510%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net472

  • 🟥 allocated_mem [+1.307KB; +1.307KB] or [+105.746%; +105.759%]
  • 🟥 throughput [-265320.598op/s; -258597.115op/s] or [-27.091%; -26.404%]

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

  • 🟥 allocated_mem [+471 bytes; +472 bytes] or [+38.558%; +38.566%]
  • 🟩 execution_time [-26.256ms; -21.385ms] or [-11.709%; -9.537%]

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

  • 🟥 allocated_mem [+1.272KB; +1.272KB] or [+105.292%; +105.304%]
  • 🟥 throughput [-146096.015op/s; -130168.377op/s] or [-20.991%; -18.703%]

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

  • 🟩 throughput [+10512.905op/s; +13489.753op/s] or [+6.689%; +8.583%]

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

  • 🟩 throughput [+6481.480op/s; +9157.832op/s] or [+5.163%; +7.295%]

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

  • 🟩 throughput [+404270.247op/s; +428484.365op/s] or [+13.480%; +14.288%]

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

  • 🟩 execution_time [-18.436ms; -14.068ms] or [-8.498%; -6.485%]
  • 🟩 throughput [+173095.082op/s; +226610.263op/s] or [+6.871%; +8.995%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs net472

  • 🟥 execution_time [+299.967ms; +300.571ms] or [+149.883%; +150.185%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs net6.0

  • 🟥 execution_time [+299.453ms; +302.882ms] or [+151.015%; +152.744%]

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

  • 🟥 execution_time [+300.144ms; +302.837ms] or [+151.189%; +152.546%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net472

  • 🟥 execution_time [+297.430ms; +298.004ms] or [+146.086%; +146.368%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net6.0

  • 🟥 execution_time [+297.456ms; +299.092ms] or [+145.415%; +146.215%]

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

  • 🟥 execution_time [+300.254ms; +301.290ms] or [+150.066%; +150.584%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark net6.0

  • 🟥 execution_time [+22.320µs; +49.100µs] or [+5.119%; +11.261%]
  • 🟥 throughput [-239.664op/s; -119.220op/s] or [-10.420%; -5.183%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack net6.0

  • 🟥 execution_time [+32.287µs; +55.950µs] or [+10.308%; +17.862%]
  • 🟥 throughput [-508.068op/s; -309.185op/s] or [-15.838%; -9.638%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net472

  • 🟥 execution_time [+299.785ms; +300.452ms] or [+149.624%; +149.957%]

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

  • unstable execution_time [+356.283ms; +390.086ms] or [+387.116%; +423.844%]
  • 🟩 throughput [+1115.982op/s; +1262.316op/s] or [+9.170%; +10.373%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest netcoreapp3.1

  • unstable execution_time [+260.925ms; +303.415ms] or [+198.118%; +230.380%]
  • 🟩 throughput [+615.336op/s; +825.619op/s] or [+5.957%; +7.993%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • unstable execution_time [+292.656ms; +352.849ms] or [+134.560%; +162.237%]
  • 🟥 throughput [-505.054op/s; -439.583op/s] or [-45.763%; -39.831%]

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

  • unstable execution_time [+204.962ms; +338.181ms] or [+87.346%; +144.119%]
  • 🟥 throughput [-744.483op/s; -661.057op/s] or [-49.657%; -44.093%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1

  • 🟥 execution_time [+343.037ms; +351.138ms] or [+205.176%; +210.022%]
  • 🟥 throughput [-404.358op/s; -369.307op/s] or [-28.155%; -25.714%]

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

  • 🟩 execution_time [-173.257µs; -137.422µs] or [-8.777%; -6.961%]
  • 🟩 throughput [+39.672op/s; +49.277op/s] or [+7.832%; +9.728%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch net472

  • 🟥 execution_time [+304.831ms; +306.186ms] or [+153.507%; +154.189%]

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

  • 🟥 execution_time [+300.995ms; +302.545ms] or [+150.829%; +151.606%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch netcoreapp3.1

  • 🟥 execution_time [+300.318ms; +303.554ms] or [+150.867%; +152.493%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net472

  • 🟥 execution_time [+303.747ms; +305.464ms] or [+152.532%; +153.394%]

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

  • 🟥 execution_time [+299.142ms; +300.861ms] or [+147.912%; +148.762%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync netcoreapp3.1

  • 🟥 execution_time [+303.560ms; +307.338ms] or [+153.858%; +155.772%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net472

  • 🟥 execution_time [+305.361ms; +306.921ms] or [+153.264%; +154.047%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net6.0

  • 🟥 execution_time [+299.776ms; +302.194ms] or [+149.411%; +150.616%]
  • 🟩 throughput [+45137.576op/s; +50802.677op/s] or [+8.963%; +10.088%]

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

  • 🟥 execution_time [+302.915ms; +305.913ms] or [+150.698%; +152.189%]

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

  • 🟩 execution_time [-16.757ms; -13.091ms] or [-7.792%; -6.088%]
  • 🟩 throughput [+19179.495op/s; +26740.430op/s] or [+5.261%; +7.336%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark net472

  • unstable execution_time [+9.714µs; +51.448µs] or [+2.400%; +12.708%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark net6.0

  • 🟩 allocated_mem [-19.644KB; -19.623KB] or [-7.166%; -7.158%]
  • unstable execution_time [-47.486µs; +4.809µs] or [-9.385%; +0.950%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net6.0

  • 🟥 execution_time [+6.687µs; +10.852µs] or [+15.806%; +25.650%]
  • 🟥 throughput [-4851.081op/s; -3083.135op/s] or [-20.422%; -12.979%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark netcoreapp3.1

  • unstable execution_time [-12.752µs; -5.418µs] or [-19.785%; -8.405%]
  • 🟩 throughput [+1337.152op/s; +2885.834op/s] or [+8.204%; +17.706%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net472

  • 🟥 execution_time [+302.238ms; +305.392ms] or [+152.768%; +154.362%]

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

  • 🟥 execution_time [+303.818ms; +306.708ms] or [+154.642%; +156.114%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog netcoreapp3.1

  • 🟥 execution_time [+299.631ms; +301.915ms] or [+150.002%; +151.146%]

scenario:Benchmarks.Trace.RedisBenchmark.SendReceive net472

  • 🟥 throughput [-26447.326op/s; -24688.160op/s] or [-7.321%; -6.834%]

scenario:Benchmarks.Trace.RedisBenchmark.SendReceive net6.0

  • 🟩 throughput [+38473.933op/s; +40366.455op/s] or [+7.282%; +7.641%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog net472

  • 🟥 execution_time [+298.858ms; +300.563ms] or [+148.954%; +149.803%]

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

  • 🟥 execution_time [+301.534ms; +302.664ms] or [+151.416%; +151.983%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog netcoreapp3.1

  • 🟥 execution_time [+304.270ms; +307.199ms] or [+154.306%; +155.791%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net472

  • 🟥 execution_time [+300.370ms; +301.058ms] or [+149.826%; +150.169%]
  • 🟩 throughput [+66090429.919op/s; +66363168.517op/s] or [+48.131%; +48.330%]

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

  • 🟥 execution_time [+423.950ms; +427.991ms] or [+527.257%; +532.283%]
  • 🟩 throughput [+1055.538op/s; +1223.858op/s] or [+8.160%; +9.461%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore netcoreapp3.1

  • 🟥 execution_time [+299.276ms; +300.176ms] or [+149.272%; +149.721%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net6.0

  • 🟩 throughput [+84825.270op/s; +98581.024op/s] or [+7.920%; +9.204%]

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

  • 🟩 throughput [+54430.054op/s; +73390.638op/s] or [+6.300%; +8.495%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan net6.0

  • 🟩 throughput [+75286.567op/s; +107027.169op/s] or [+5.827%; +8.284%]

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

  • 🟩 throughput [+83191.747op/s; +91923.860op/s] or [+8.262%; +9.130%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes net6.0

  • 🟩 throughput [+51030.635op/s; +57073.876op/s] or [+9.266%; +10.364%]

scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net6.0

  • 🟩 throughput [+66885.813op/s; +85036.776op/s] or [+7.473%; +9.501%]

Known flaky benchmarks without significant changes:

  • scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net472
  • scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild netcoreapp3.1
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody net472
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody net472
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark net472
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark netcoreapp3.1
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack net472
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net6.0
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net6.0
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice netcoreapp3.1
  • scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog net472
  • scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog netcoreapp3.1
  • scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark netcoreapp3.1
  • scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net472
  • scenario:Benchmarks.Trace.RedisBenchmark.SendReceive netcoreapp3.1
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes netcoreapp3.1
  • scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net472
  • scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin netcoreapp3.1

@andrewlock andrewlock force-pushed the andrew/update-vendors-4 branch from ef58938 to 7dc44a2 Compare April 21, 2026 10:19
@andrewlock andrewlock force-pushed the andrew/update-vendors-7 branch from 3af08ab to 528b407 Compare April 21, 2026 10:19
@andrewlock andrewlock force-pushed the andrew/update-vendors-4 branch from 7dc44a2 to 481fbc2 Compare April 23, 2026 07:20
Base automatically changed from andrew/update-vendors-4 to master April 23, 2026 09:06
@andrewlock andrewlock force-pushed the andrew/update-vendors-7 branch from 528b407 to 112589a Compare April 23, 2026 09:27
@andrewlock andrewlock enabled auto-merge (squash) April 23, 2026 09:27
Copy link
Copy Markdown
Collaborator

@NachoEchevarria NachoEchevarria left a comment

Choose a reason for hiding this comment

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

Nice! Quick question: is the ultimate goal to stop using dotnet-vendored-code eventually?

@andrewlock andrewlock merged commit 7520173 into master Apr 23, 2026
140 of 141 checks passed
@andrewlock andrewlock deleted the andrew/update-vendors-7 branch April 23, 2026 11:08
@github-actions github-actions Bot added this to the vNext-v3 milestone Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos area:vendors Code from other vendors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants