Use the built-in System.Reflection.Metadata types for .NET Core#8454
Use the built-in System.Reflection.Metadata types for .NET Core#8454andrewlock merged 10 commits intomasterfrom
Conversation
BenchmarksBenchmark execution time: 2026-04-22 11:56:39 Comparing candidate commit 1cd4ff9 in PR branch Found 0 performance improvements and 1 performance regressions! Performance is the same for 26 metrics, 0 unstable metrics, 59 known flaky benchmarks, 28 flaky benchmarks without significant changes.
|
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (8454) and master. ✅ No regressions detected - check the details below Full Metrics ComparisonFakeDbCommand
HttpMessageHandler
Comparison explanationExecution-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 highlighted 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). Duration chartsFakeDbCommand (.NET Framework 4.8)gantt
title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8454) - mean (75ms) : 71, 79
master - mean (75ms) : 71, 78
section Bailout
This PR (8454) - mean (78ms) : 75, 82
master - mean (78ms) : 74, 81
section CallTarget+Inlining+NGEN
This PR (8454) - mean (1,072ms) : 1033, 1111
master - mean (1,073ms) : 1030, 1117
FakeDbCommand (.NET Core 3.1)gantt
title Execution time (ms) FakeDbCommand (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8454) - mean (118ms) : 112, 124
master - mean (117ms) : 111, 123
section Bailout
This PR (8454) - mean (116ms) : 111, 120
master - mean (115ms) : 112, 119
section CallTarget+Inlining+NGEN
This PR (8454) - mean (775ms) : 749, 801
master - mean (793ms) : 766, 821
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8454) - mean (103ms) : 98, 109
master - mean (103ms) : 98, 108
section Bailout
This PR (8454) - mean (102ms) : 100, 104
master - mean (103ms) : 99, 108
section CallTarget+Inlining+NGEN
This PR (8454) - mean (939ms) : 898, 980
master - mean (940ms) : 905, 974
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8454) - mean (101ms) : 96, 105
master - mean (99ms) : 95, 103
section Bailout
This PR (8454) - mean (104ms) : 99, 109
master - mean (103ms) : 98, 107
section CallTarget+Inlining+NGEN
This PR (8454) - mean (819ms) : 784, 854
master - mean (826ms) : 786, 865
HttpMessageHandler (.NET Framework 4.8)gantt
title Execution time (ms) HttpMessageHandler (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8454) - mean (211ms) : 205, 217
master - mean (205ms) : 200, 210
section Bailout
This PR (8454) - mean (215ms) : 210, 220
master - mean (208ms) : 204, 212
section CallTarget+Inlining+NGEN
This PR (8454) - mean (1,237ms) : 1186, 1287
master - mean (1,197ms) : 1155, 1238
HttpMessageHandler (.NET Core 3.1)gantt
title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8454) - mean (307ms) : 300, 313
master - mean (293ms) : 286, 300
section Bailout
This PR (8454) - mean (309ms) : 302, 316
master - mean (294ms) : 288, 299
section CallTarget+Inlining+NGEN
This PR (8454) - mean (999ms) : 973, 1024
master - mean (978ms) : 939, 1017
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8454) - mean (302ms) : 293, 312
master - mean (288ms) : 281, 296
section Bailout
This PR (8454) - mean (296ms) : 287, 305
master - mean (286ms) : 282, 291
section CallTarget+Inlining+NGEN
This PR (8454) - mean (1,177ms) : 1131, 1223
master - mean (1,163ms) : 1129, 1198
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8454) - mean (295ms) : 279, 311
master - mean (285ms) : 278, 293
section Bailout
This PR (8454) - mean (291ms) : 285, 297
master - mean (287ms) : 281, 293
section CallTarget+Inlining+NGEN
This PR (8454) - mean (1,071ms) : 985, 1156
master - mean (1,055ms) : 1003, 1107
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
9f49119 to
7ea4e03
Compare
9f055d8 to
fa2694a
Compare
7ea4e03 to
ffcd2fb
Compare
fa2694a to
0257651
Compare
0257651 to
1cd4ff9
Compare
bouwkast
left a comment
There was a problem hiding this comment.
LGTM
How did you calculate the estimated size stuff? I'm assuming just looking at the properties of the output in the file explorer?
Tool by this random guy (@lucaspimentel) 😄 https://github.com/lucaspimentel/analyze-assembly-size |
## Summary of changes - Remove some unused types from System.Reflection.Metadata (mostly around builder/writer infrastructure that was unused) - Update the vendored version of System.Reflection.Metadata to use the runtime repo directly, and bump to latest patch version ## Reason for change We want to update our vendored .NET library versions. ## Implementation details - Make the vendoring repeatable - Run the tool, check for errors, tweak, rinse and repeat - After running the tool, used 🤖 to identify segments of code that weren't used, so we could strip them out ## Test coverage This is the test, if it compiles and tests pass, we should be ok 🤞 ## Other details https://datadoghq.atlassian.net/browse/APMLP-1207 Part of a stack updating our vendored system code - #8391 - #8454
| #if NETCOREAPP | ||
| using System.Reflection.Metadata; | ||
| #else | ||
| using Datadog.Trace.VendoredMicrosoftCode.System.Reflection.Metadata; | ||
| #endif |
There was a problem hiding this comment.
We've been handling these here: https://github.com/DataDog/dd-trace-dotnet/blob/master/tracer/src/Datadog.Trace/GlobalUsings.cs
Was it intentional to not do it in this case?
(edit: comment applies to several files in this PR)
There was a problem hiding this comment.
Yes, it was intentional. Unfortunately, there's a lot of overlap in type names between System.Reflection.Metadata and dnlib, such that adding this to global using causes a bunch of namespace conflicts in both dnlib code and Newtonsoft.JSON. Rather than have to change how those libraries are vendored, I figured it was probably better to just accept this here.
Given these are all pollyfilling system libraries, part of me wonders if it wouldn't be better to just keep their original namespaces 🤷♂️
## Summary of changes - Update the System.Memory based on NuGet package sources ## Reason for change We want to update our vendored .NET library versions. ## Implementation details - Make the vendoring repeatable - Run the tool, check for errors, tweak, rinse and repeat - After running the tool, used 🤖 to identify segments of code that weren't used, so we could strip them out The updated vendoring is based on the public [System.Memory](https://www.nuget.org/packages/System.Memory/4.6.3#dependencies-body-tab) nuget package, so is designed to be used with .NET Framework and .NET Standard, so makes the most sense to use IMO. As this package also uses _System.Buffers_ and _System.Numerics.Vectors_, vendored those pieces we need where appropriate. ## Test coverage This is the test, if it compiles and tests pass, we should be ok 🤞 ## Other details https://datadoghq.atlassian.net/browse/APMLP-1207 Note that currently, there's a lot of `Utf8Formatter` code that _isn't_ used, and could be excluded, however, given that theoretically we could/should use this in the future. I'm torn whether to just leave it in, or whether to tear it out for now, and restore it if/when we want to use it later. Any thoughts? Part of a stack updating our vendored system code - #8391 - #8454 - #8455
## Summary of changes Stop vendoring the `SR` + regex files for microsoft code ## Reason for change Using `ResourceManager` is overkill, as we don't deploy all the translations etc anyway, and don't want to. ## Implementation details Replaced all the `SR.` accesses in previous PRs, so this is now dead code that we can remove. ## Test coverage If it builds, we're good ## Other details https://datadoghq.atlassian.net/browse/APMLP-1207 Note that currently, there's a lot of `Utf8Formatter` code that _isn't_ used, and could be excluded, however, given that theoretically we could/should use this in the future. I'm torn whether to just leave it in, or whether to tear it out for now, and restore it if/when we want to use it later. Any thoughts? Part of a stack updating our vendored system code - #8391 - #8454 - #8455 - #8459
## 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](https://nuget.info/packages/System.Runtime.CompilerServices.Unsafe/6.1.2), the [source code](https://github.com/dotnet/maintenance-packages/blob/14e29655e53aec37342e933bfd7ba574167453ff/src/System.Runtime.CompilerServices.Unsafe/src/System.Runtime.CompilerServices.Unsafe.il) is written directly as IL, and [compiled using Ilasm.exe](https://learn.microsoft.com/en-us/dotnet/framework/tools/ilasm-exe-il-assembler). 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 - #8391 - #8454 - #8455 - #8459 - #8461
#8476) ## Summary of changes Updates the System.Memory vendoring code to move types like `ReadOnlySpan<T>`, `Span<T>` into `System` instead of `Datadog.Trace.VendoredMicrosoftCode.System` ## Reason for change The compiler has various functionality that relies on the `Span<T>` (and `ReadOnlySpan<T>`) being available in the `System` namespace. By making this change, we get the advantage of those types being available. A separate PR will actually update code to use those types, except where changes were required to make it compile in this PR. ## Implementation details Update the vendoring code to stop changing the namespace. ## Test coverage This is the test, if the tests pass, we should be fine. ## Other details Depends on a stack updating our vendored system code - #8391 - #8454 - #8455 - #8459 - #8461 - #8469
## Summary of changes Remove some branching code that's no longer required after #8476 moved `Span<T>` to `System` namespace ## Reason for change This sort of stuff is the _reason_ we made that change, to reduce maintenance. ## Implementation details Set 🤖 looking for possible cases, so it's not exhaustive, but gives a taster. I think most of these make sense. It's nothing outstanding but it's the little things. ## Test coverage Just a refactoring, so covered by existing tests. ## Other details By definition, we don't really expect to see performance improvements for this, other than potentially some reduced allocation in .NET Framework. The primary benefits are devx Depends on the vendoring code stack: Depends on a stack updating our vendored system code - #8391 - #8454 - #8455 - #8459 - #8461 - #8469 - #8476 --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
#8486) ## Summary of changes Update the tag list generator to always use `ReadOnlySpan<byte>` properties instead of `byte[]` ## Reason for change After moving our vendored `Span<T>` implementation into the `System` namespace, various optimizations open up to us, including using `ReadOnlySpan<byte>` properties on .NET Framework instead of `static readonly byte[]` to avoid startup costs. ## Implementation details Replace the code generated by the generator, and update the generated code ## Test coverage Covered by snapshot tests and behaviour is covered by existing tests. We'll check the benchmarks to make sure that we _don't_ see any perf impact (there shouldn't be, impact should just be reduced startup costs) ## Other details Depends on a stack updating our vendored system code - #8391 - #8454 - #8455 - #8459 - #8461 - #8469 - #8476 - #8477
… string literals (#8487) ## Summary of changes Convert `Encoding.Utf8.GetBytes` calls to static constants using UTF8 string literals ## Reason for change After moving our vendored `Span<T>` implementation into the `System` namespace, various optimizations open up to us, including using UTF-8 string literals, to encode strings to UTF-8 at compile time instead of at runtime. By combing with `static ReadOnlySpan<byte>` properties, these also become zero allocation, so we get reduced overall memory usage as well as better startup time ## Implementation details Replace the following with utf8 string literals: - `StringEncoding.UTF8.GetBytes` - `Encoding.UTF8.GetBytes` - `EncodingHelpers.UTF8NoBom.GetBytes` ## Test coverage All covered by existing tests ## Other details Depends on a stack updating our vendored system code - #8391 - #8454 - #8455 - #8459 - #8461 - #8469 - #8476 - #8477 - #8486
Summary of changes
Use the built-in System.Reflection.Metadata types for .NET Core 3.1+
Reason for change
In #6726, we switched from always using the vendored System.Memory and other BCL types, to using the built-in versions for .NET Core 3.1 where they're available. This was done with the goal of reducing artifact size, while also hopefully improving consistency, and potentially improving performance.
Separately, we're working on updating our vendored code to make updating it more repeatable (see #8391). This flagged a variety of modifications we'd made to the vendored System.Reflection.Metadata code to be able to use internal members.
Rather than include those modifications in the updated vendored code, this PR updates our existing usages to not use those internal members in any scenario. This also means we can stop using the vendored code for .NET Core 3.1+.
Implementation details
Hashtype used by Debugger code, which was internal to System.Reflection.MetadataFNV1aHash, it isn't usingFNV1a, so I chose to call it simple hash (as that's what it's doing, a simple "hash code" calculation).GlobalUsings.cs, because doing so causes a variety of namespace collisions across our vendored code (Newtonsoft.Json, dnlib)usingstatements needed removing.MethodDefinitionFromRowId.MethodDefinition.Handlewas a little more painful, as it required more refactoring, but fundamentally we were always deriving aMethodDefinitionfrom aMethodDefinitionHandle, so the changes are mostly a minor inconvenience, but they now only use public APIs.Test coverage
Should be covered by existing tests; all these changes are just "refactorings", nothing additional.
Assembly size comparison
netcoreapp3.1net6.0Estimated size per namespace
Before (
net6.0)After (
net6.0) (all gone)Other details
https://datadoghq.atlassian.net/browse/APMLP-1207
Part of a stack updating our vendored system code