Use built-in .NET runtime types instead of vendored types when possible#6726
Use built-in .NET runtime types instead of vendored types when possible#6726dudikeleti merged 17 commits intomasterfrom
Conversation
1f37cc8 to
6dd35fd
Compare
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
d09bc2e to
0b047b0
Compare
55471b6 to
539552b
Compare
539552b to
b00f219
Compare
d2f9b4c to
0153f8e
Compare
c9cdab8 to
e440e8d
Compare
4fdc3e6 to
628ae33
Compare
c8960e5 to
fba1250
Compare
fba1250 to
a006f05
Compare
a006f05 to
3acc23d
Compare
3acc23d to
e68663f
Compare
BenchmarksBenchmark execution time: 2026-02-04 10:25:44 Comparing candidate commit 56adc55 in PR branch Found 10 performance improvements and 8 performance regressions! Performance is the same for 158 metrics, 16 unstable metrics. scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net6.0
scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody netcoreapp3.1
scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net6.0
scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs netcoreapp3.1
scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472
scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1
scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net6.0
scenario:Benchmarks.Trace.DbCommandBenchmark.ExecuteNonQuery net6.0
scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net472
scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync netcoreapp3.1
scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog net6.0
scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net472
scenario:Benchmarks.Trace.RedisBenchmark.SendReceive netcoreapp3.1
scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore netcoreapp3.1
scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan net6.0
scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan netcoreapp3.1
|
429f902 to
43aaa8e
Compare
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (6726) 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 (6726) - mean (73ms) : 71, 74
master - mean (73ms) : 71, 75
section Bailout
This PR (6726) - mean (77ms) : 76, 78
master - mean (78ms) : 76, 79
section CallTarget+Inlining+NGEN
This PR (6726) - mean (1,068ms) : 1016, 1120
master - mean (1,066ms) : 1013, 1119
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 (6726) - mean (124ms) : 121, 126
master - mean (125ms) : 120, 129
section Bailout
This PR (6726) - mean (125ms) : 123, 126
master - mean (126ms) : 123, 129
section CallTarget+Inlining+NGEN
This PR (6726) - mean (819ms) : 769, 870
master - mean (833ms) : 780, 886
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (6726) - mean (108ms) : 105, 111
master - mean (102ms) : 99, 106
section Bailout
This PR (6726) - mean (109ms) : crit, 107, 112
master - mean (103ms) : 100, 106
section CallTarget+Inlining+NGEN
This PR (6726) - mean (792ms) : crit, 770, 814
master - mean (742ms) : 666, 817
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (6726) - mean (107ms) : 104, 111
master - mean (108ms) : 105, 110
section Bailout
This PR (6726) - mean (108ms) : 106, 110
master - mean (108ms) : 106, 110
section CallTarget+Inlining+NGEN
This PR (6726) - mean (701ms) : 682, 720
master - mean (712ms) : 690, 735
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 (6726) - mean (199ms) : 195, 204
master - mean (198ms) : 192, 204
section Bailout
This PR (6726) - mean (201ms) : 196, 205
master - mean (201ms) : 198, 205
section CallTarget+Inlining+NGEN
This PR (6726) - mean (1,163ms) : 1110, 1216
master - mean (1,170ms) : 1104, 1235
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 (6726) - mean (296ms) : 289, 303
master - mean (285ms) : 279, 291
section Bailout
This PR (6726) - mean (297ms) : 292, 302
master - mean (285ms) : 278, 293
section CallTarget+Inlining+NGEN
This PR (6726) - mean (994ms) : 949, 1039
master - mean (960ms) : 887, 1033
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (6726) - mean (289ms) : 280, 297
master - mean (289ms) : 280, 299
section Bailout
This PR (6726) - mean (288ms) : 281, 295
master - mean (289ms) : 285, 294
section CallTarget+Inlining+NGEN
This PR (6726) - mean (991ms) : 950, 1031
master - mean (998ms) : 959, 1038
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (6726) - mean (288ms) : 282, 293
master - mean (288ms) : 281, 295
section Bailout
This PR (6726) - mean (287ms) : 280, 294
master - mean (289ms) : 282, 295
section CallTarget+Inlining+NGEN
This PR (6726) - mean (882ms) : 848, 916
master - mean (892ms) : 861, 922
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
andrewlock
left a comment
There was a problem hiding this comment.
LGTM, a few questions/nits/improvements. We should almost certainly remove the vendored attributes, but we can address those separately I think
| var newMemory = ArrayMemoryPool<T>.Shared.Rent(currentSize * 2); | ||
| var newMemory = MemoryPool<T>.Shared.Rent(currentSize * 2); |
There was a problem hiding this comment.
For reviewers, this looks like it might be a change to worry about given that ArrayMemoryPool derives from MemoryPool. But the MemoryPool<T>.Shared instance is actually an instance of ArrayMemoryPool<T> so this whole code is effectively identical
There was a problem hiding this comment.
The static Shared property is actually on the MemoryPool<T> type and you can't override static members, so we were always using that one. This would compile to MemoryPool<T>.Shared.
| #nullable enable | ||
|
|
||
| #if !NETCOREAPP | ||
| #if !NETCOREAPP3_1_OR_GREATER |
There was a problem hiding this comment.
There's a potential future where we don't ship a netstandard dll, and instead ship a .NET Core 2.x dll. In that future, this code path won't be hit, whereas it would otherwise, so setting the "real" minimum level is generally preferable. Is this really .NET Core 3.1+, or really .NET Core 2.x+?
There was a problem hiding this comment.
Just like the NETCOREAPP3_0_OR_GREATER comment elsewhere, I was just trying to be consistent. Also, we're talking about .NET Core 2.x, so... meh?
There was a problem hiding this comment.
fwiw it looks like we don't need this #if at all anymore? it looks like GlobalUsings.cs is handling this correctly.
There was a problem hiding this comment.
...ish. It's still using the vendored Unsafe.ReadUnaligned in .NET Core 3.1 even though that method was added in .NET Core 3.0. It might be a similar issue to UnSafe.IsNullRef() which was added in .NET 5.
There was a problem hiding this comment.
Also, we're talking about .NET Core 2.x,
Yeah, I mean... that was the original 3.x plan 😅 Because it's actually a big improvement over netstandard, but you know, reasons...
It's still using the vendored Unsafe.ReadUnaligned in .NET Core 3.1
I mean, we're using the vendored Unsafe everywhere for 3.1 now 😉
| /// </summary> | ||
| internal static class EnumerableExtensions | ||
| { | ||
| public static T? FirstOrDefault<T>(this ImmutableArray<T> collection, Func<T, bool> predicate) |
There was a problem hiding this comment.
For reviewers: These two are deleted for the reasons described in the comment above:
/// <summary>
/// Replacements for System.Linq to avoid an unnecessary dependency.
/// Parameter and return types strengthened to actual internal usage as an optimization.
/// </summary>Seeing as we do reference System.Linq, they're both unecessary, and cause ambiguity. Also, they're trivial implementations, so doesn't seem like we're really losing anything there
- The nullable attributes won't actually work, they need to be in the correct namespace, and we already polyfill those - The LibraryImport attribute drives a source generator, but that generator is only present in .NET 7+, so it does nothing here. - This also simplifies the vendoring in general
6039658 to
56adc55
Compare
There was a problem hiding this comment.
Pull request overview
Updates the tracer to prefer built-in .NET runtime types (e.g., System.Buffers, System.Collections.Immutable, MemoryPool<T>, Unsafe) on .NET Core 3.1+ and reduce artifact size by excluding vendored runtime sources when they’re already available in the target runtime.
Changes:
- Centralized TFM-based selection of built-in vs vendored BCL types via
GlobalUsings.cs. - Updated code to use public BCL APIs (
MemoryPool<T>,ImmutableArray.CreateBuilder<T>(),Unsafe.IsNullRef) and added/updated reference snapshots. - Adjusted build/trimming configuration to exclude vendored runtime sources on
netcoreapp3.1+while keepingSystem.Reflection.Metadatavendored for internal-member access.
Reviewed changes
Copilot reviewed 129 out of 131 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tracer/test/Datadog.Trace.Tests/VendoredCodeTests.cs | Adjusts Unsafe vendored-vs-built-in verification tests by TFM. |
| tracer/test/Datadog.Trace.Tests/Snapshots/PublicApiTests.Datadog.Trace.AssemblyReferencesHaveNotChanged.netcoreapp3.1.verified.txt | Updates expected assembly references after switching to built-in System.Collections.Immutable on netcoreapp3.1. |
| tracer/test/Datadog.Trace.Tests/Snapshots/PublicApiTests.Datadog.Trace.AssemblyReferencesHaveNotChanged.net6.0.verified.txt | Updates expected assembly references to include built-in System.Collections.Immutable on net6.0. |
| tracer/test/Datadog.Trace.Tests/Debugger/EndpointDetectorTests.cs | Uses built-in System.Collections.Immutable on netcoreapp3.1+ and vendored otherwise. |
| tracer/test/Datadog.Trace.Debugger.IntegrationTests/LineProbeResolverTest.cs | Uses built-in System.Collections.Immutable on netcoreapp3.1+ and vendored otherwise. |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Throw.cs | Switches from vendored CodeAnalysis to built-in System.Diagnostics.CodeAnalysis. |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEReader.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEMemoryBlock.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEHeaders.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEBuilder.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/ManagedPEBuilder.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/DebugDirectory/PdbChecksumDebugDirectoryData.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/DebugDirectory/DebugDirectoryBuilder.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeSystem/TypeDefinition.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeSystem/StandaloneSignature.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeSystem/PropertyDefinition.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeSystem/NamespaceDefinition.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeSystem/MethodSpecification.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeSystem/EventDefinition.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeSystem/16HandleCollections.TypeSystem.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeSystem/15HandleCollections.TypeSystem.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Signatures/MethodSignature.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Signatures/CustomAttributeValue.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Signatures/ArrayShape.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/PortablePdb/DebugMetadataHeader.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/MetadataReaderProvider.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/MetadataReader.netstandard.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Internal/NamespaceData.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Internal/NamespaceCache.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Internal/MetadataWriterUtilities.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/IL/MethodBodyBlock.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/SignatureDecoder.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/SerializedMetadataHeaps.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/PortablePdbBuilder.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/MetadataSizes.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/MetadataRootBuilder.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/MetadataBuilder.cs | Switches helper usage to LINQ (adds System.Linq) and removes vendored immutable import. |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/MetadataAggregator.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/Encoding/ControlFlowBuilder.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/Encoding/5BlobEncoders.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/Encoding/21BlobEncoders.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/CustomAttributeDecoder.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/Decoding/IConstructedTypeProvider.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/BlobWriter.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/BlobContentId.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Metadata/BlobBuilder.cs | Switches helper usage to LINQ (adds System.Linq) and removes vendored immutable import. |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/Interop.cs | Drops vendored interop import and removes unused LibraryImport attribute usage. |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/ImmutableMemoryStream.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/ImmutableByteArrayInterop.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/EnumerableExtensions.cs | Removes custom LINQ-like helpers and vendored immutable import. |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/ByteSequenceComparer.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BlobUtilities.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Internal/MemoryBlocks/ByteArrayMemoryProvider.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Internal/MemoryBlocks/ByteArrayMemoryBlock.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Reflection.Metadata/src/System/Reflection/Internal/MemoryBlocks/AbstractMemoryBlock.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Private.CoreLib/src/System/Runtime/InteropServices/StringMarshalling.cs | Deletes unused vendored StringMarshalling enum. |
| tracer/src/Datadog.Trace/Vendors/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs | Deletes unused vendored LibraryImportAttribute. |
| tracer/src/Datadog.Trace/Vendors/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs | Deletes vendored nullable attribute stub (deprecated/unusable). |
| tracer/src/Datadog.Trace/Vendors/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/9NullableAttributes.cs | Deletes vendored nullable attribute stub (deprecated/unusable). |
| tracer/src/Datadog.Trace/Vendors/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/8NullableAttributes.cs | Deletes vendored nullable attribute stub (deprecated/unusable). |
| tracer/src/Datadog.Trace/Vendors/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/7NullableAttributes.cs | Deletes vendored nullable attribute stub (deprecated/unusable). |
| tracer/src/Datadog.Trace/Vendors/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/6NullableAttributes.cs | Deletes vendored nullable attribute stub (deprecated/unusable). |
| tracer/src/Datadog.Trace/Vendors/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/5NullableAttributes.cs | Deletes vendored nullable attribute stub (deprecated/unusable). |
| tracer/src/Datadog.Trace/Vendors/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/4NullableAttributes.cs | Deletes vendored nullable attribute stub (deprecated/unusable). |
| tracer/src/Datadog.Trace/Vendors/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/3NullableAttributes.cs | Deletes vendored nullable attribute stub (deprecated/unusable). |
| tracer/src/Datadog.Trace/Vendors/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/2NullableAttributes.cs | Deletes vendored nullable attribute stub (deprecated/unusable). |
| tracer/src/Datadog.Trace/Vendors/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/1NullableAttributes.cs | Deletes vendored nullable attribute stub (deprecated/unusable). |
| tracer/src/Datadog.Trace/Vendors/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/10NullableAttributes.cs | Deletes vendored nullable attribute stub (deprecated/unusable). |
| tracer/src/Datadog.Trace/Vendors/System.Memory/Span`1.cs | Removes explicit vendored aliases/imports (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Memory/SpanHelpers.cs | Removes explicit vendored aliases/imports (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Memory/SpanDebugView`1.cs | Removes vendored diagnostics import. |
| tracer/src/Datadog.Trace/Vendors/System.Memory/Runtime/InteropServices/MemoryMarshal.cs | Switches to built-in System.Runtime.InteropServices import usage. |
| tracer/src/Datadog.Trace/Vendors/System.Memory/ReadOnlySpan`1.cs | Removes explicit vendored Unsafe alias (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Memory/ReadOnlyMemory`1.cs | Removes explicit vendored aliases/imports (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Memory/Memory`1.cs | Removes explicit vendored aliases/imports (relying on global usings). |
| tracer/src/Datadog.Trace/Vendors/System.Memory/MemoryExtensions.cs | Uses built-in System.Runtime.InteropServices import. |
| tracer/src/Datadog.Trace/Vendors/System.Memory/Buffers/Utilities.cs | Uses built-in System.Runtime.InteropServices import and removes vendored aliases. |
| tracer/src/Datadog.Trace/Vendors/System.Memory/Buffers/Text/Base64.cs | Uses built-in System.Runtime.InteropServices import and removes vendored aliases. |
| tracer/src/Datadog.Trace/Vendors/System.Memory/Buffers/ReadOnlySequence`1.cs | Uses built-in System.Runtime.InteropServices import and removes vendored aliases. |
| tracer/src/Datadog.Trace/Vendors/System.Memory/Buffers/ReadOnlySequenceDebugView`1.cs | Removes vendored diagnostics import. |
| tracer/src/Datadog.Trace/Vendors/System.Collections.Immutable/src/System/Linq/ImmutableArrayExtensions.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Util/Streams/InitiallyBufferedStream.cs | Removes vendored System.Buffers import (relying on global usings). |
| tracer/src/Datadog.Trace/Util/HexString.cs | Switches to built-in interop types on netcoreapp3.1+ and shim otherwise. |
| tracer/src/Datadog.Trace/Util/BitConverterShim.cs | Updates shim compilation condition for netcoreapp3.1+ and relies on global usings. |
| tracer/src/Datadog.Trace/Propagators/W3CBaggagePropagator.cs | Removes vendored System.Buffers import (relying on global usings). |
| tracer/src/Datadog.Trace/PDBs/DatadogMetadataReader.cs | Switches to MemoryPool<T> and built-in ImmutableArray builder APIs; keeps vendored metadata. |
| tracer/src/Datadog.Trace/PDBs/DatadogMetadataReader.Dnlib.cs | Switches to MemoryPool<T> and built-in ImmutableArray builder APIs. |
| tracer/src/Datadog.Trace/HttpOverStreams/ChunkedEncodingReadStream.HexHelpers.cs | Removes per-file conditional usings (relying on global usings). |
| tracer/src/Datadog.Trace/GlobalUsings.cs | Adds TFM-based global usings for built-in vs vendored BCL types and Unsafe alias selection. |
| tracer/src/Datadog.Trace/Debugger/Symbols/Utf8CountingPooledTextWriter.cs | Removes vendored System.Buffers import (relying on global usings). |
| tracer/src/Datadog.Trace/Debugger/Symbols/TypeProvider.cs | Removes vendored immutable import; clarifies vendored metadata usage. |
| tracer/src/Datadog.Trace/Debugger/Symbols/SymbolsUploader.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Debugger/Symbols/SymbolsExtensions.cs | Improves nil handle initialization (readonly + default). |
| tracer/src/Datadog.Trace/Debugger/Symbols/SymbolPdbExtractor.cs | Switches to built-in Span/MemoryPool and string span helpers; keeps vendored metadata. |
| tracer/src/Datadog.Trace/Debugger/Symbols/SymbolExtractor.cs | Switches to built-in string span helpers and adjusts compiler-generated detection call. |
| tracer/src/Datadog.Trace/Debugger/Symbols/AssemblyFilter.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Debugger/SpanCodeOrigin/SpanCodeOrigin.cs | Removes vendored imports (relying on global usings). |
| tracer/src/Datadog.Trace/Debugger/SpanCodeOrigin/EndpointDetector.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Debugger/SignatureParser.cs | Removes vendored System.Buffers import (relying on global usings). |
| tracer/src/Datadog.Trace/Debugger/LineProbeResolver.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Debugger/Instrumentation/MethodDebuggerInvoker.SingleProbe.cs | Switches to Unsafe.IsNullRef via global alias. |
| tracer/src/Datadog.Trace/Debugger/Instrumentation/LineDebuggerInvoker.cs | Switches to Unsafe.IsNullRef via global alias. |
| tracer/src/Datadog.Trace/Debugger/Instrumentation/AsyncMethodDebuggerInvoker.SingleProbe.cs | Switches to Unsafe.IsNullRef via global alias. |
| tracer/src/Datadog.Trace/Debugger/Instrumentation/AsyncLineDebuggerInvoker.cs | Switches to Unsafe.IsNullRef via global alias. |
| tracer/src/Datadog.Trace/Debugger/Helpers/MemoryExtensions.cs | Switches buffer growth from ArrayMemoryPool<T> to MemoryPool<T>. |
| tracer/src/Datadog.Trace/Debugger/Expressions/MethodScopeMembers.cs | Removes vendored System.Buffers import (relying on global usings). |
| tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/ThirdParty/ThirdPartyModules.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/ThirdParty/ThirdPartyConfigurationReader.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/TestExceptionNormalizer.cs | Replaces vendored span types with BCL ReadOnlySpan<char>. |
| tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/StackTraceProcessor.cs | Replaces vendored string span helpers with BCL span APIs. |
| tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/FrameFilter.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/ExceptionNormalizer.cs | Replaces vendored string span helpers with BCL span APIs. |
| tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/ExceptionCaseInstrumentationManager.cs | Formatting-only change (blank line). |
| tracer/src/Datadog.Trace/Debugger/DebuggerSettings.cs | Removes vendored immutable import (relying on global usings). |
| tracer/src/Datadog.Trace/Debugger/Caching/DefaultMemoryChecker.cs | Uses BCL MemoryMarshal + Utf8Parser and BCL span APIs. |
| tracer/src/Datadog.Trace/Datadog.Trace.csproj | Excludes vendored runtime sources on netcoreapp3.1+ and conditionally re-adds vendored Unsafe.cs for IsNullRef. |
| tracer/src/Datadog.Trace/DatabaseMonitoring/DatabaseMonitoringPropagator.cs | Switches to BCL Span<byte> and BinaryPrimitives. |
| tracer/src/Datadog.Trace/DataStreamsMonitoring/DataStreamsContextPropagator.cs | Removes vendored buffers/text imports (relying on global usings). |
| tracer/src/Datadog.Trace/ClrProfiler/CallTarget/Handlers/Continuations/ContinuationGenerator.cs | Removes vendored Unsafe fallback and uses global Unsafe alias. |
| tracer/src/Datadog.Trace/ClrProfiler/CallTarget/CallTargetRefStruct.cs | Updates ref-struct accessors to use unqualified Span<T>/ReadOnlySpan<T> types (via global usings). |
| tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Testing/XUnit/V3/XUnitTestMethodRunnerBaseRunTestCaseV3Integration.cs | Removes vendored Unsafe import (relying on global alias). |
| tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/IbmMq/IbmMqHeadersAdapter.cs | Removes vendored Unsafe import (relying on global alias). |
| tracer/src/Datadog.Trace/Ci/Net/FileTestOptimizationClient.cs | Uses BCL CodeAnalysis attributes and tightens deserialization success check. |
| tracer/src/Datadog.Trace/Ci/Ipc/IpcDualChannel.cs | Removes vendored System.Buffers import (relying on global usings). |
| tracer/src/Datadog.Trace/Ci/Ipc/CircularChannel.Reader.cs | Removes vendored System.Buffers import (relying on global usings). |
| tracer/src/Datadog.Trace/AppSec/WafEncoding/Encoder.cs | Switches to global Unsafe.As alias. |
| tracer/src/Datadog.Trace/Agent/SpanCollection.cs | Removes per-file Unsafe alias selection (relying on global alias). |
| tracer/src/Datadog.Trace/Agent/MultipartFormItem.cs | Uses BCL CodeAnalysis attributes. |
| tracer/src/Datadog.Trace.Trimming/build/Datadog.Trace.Trimming.xml | Updates linker roots for new built-in type dependencies and removes no-longer-needed roots. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #if DEBUG | ||
| throw new Xunit.SkipException("This test requires RELEASE mode and will fail in DEBUG mode on some target frameworks"); | ||
| #else | ||
| #elif !NETCOREAPP3_1_OR_GREATER | ||
| var originalType = typeof(System.Runtime.CompilerServices.Unsafe); | ||
| var vendoredType = typeof(VendoredMicrosoftCode.System.Runtime.CompilerServices.Unsafe.Unsafe); |
There was a problem hiding this comment.
For NETCOREAPP3_1_OR_GREATER in RELEASE, this test method becomes an empty no-op (neither the DEBUG skip nor the non-NETCOREAPP block compiles), so it will silently pass without asserting anything. Add an #else branch that explicitly skips (or wrap the whole [Fact] in the same preprocessor condition) so the test outcome is meaningful on all TFMs.
| <None Remove="AppSec\Waf\ConfigFiles\apisecurity-config.json" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- we don't need the vendored .NET runtime code when targetting .NET Core 3.1+ --> |
There was a problem hiding this comment.
Correct spelling of 'targetting' to 'targeting' in the project comment.
| <!-- we don't need the vendored .NET runtime code when targetting .NET Core 3.1+ --> | |
| <!-- we don't need the vendored .NET runtime code when targeting .NET Core 3.1+ --> |
There was a problem hiding this comment.
TIL some new English rules suggestions (American vs British): https://english.stackexchange.com/questions/205815/is-targetted-a-standard-british-english-spelling
## Summary of changes Fixes the broken build ## Reason for change #6726 was merged but needed a rebase, so this slipped in ## Implementation details Don't use the non-existent "vendored" attributes. Always use the real ones ## Test coverage If the build passes, we're good
Summary of changes
When targeting .NET Core >= 3.1, do not include the files copied ("vendored") from the .NET runtime. Instead, use the built-in types.
Reason for change
Implementation details
GlobalUsings.cs, use#if NETCOREAPP3_1_OR_GREATERandglobal usingto choose namespaces based on target runtime (TFM)internal.NET runtime APIs with their public counterparts, for example:ArrayMemoryPool➡️MemoryPoolnew ImmutableArray<LocalScope>.Builder()➡️ImmutableArray.CreateBuilder<LocalScope>()netcoreapp3.1ornet6.0, exclude most of the files in:Note that this PR keeps the files in
Vendors/System.Reflection.Metadatafor now because we access non-public members from that namespace. Unfortunately, this namespace makes up about 60% of the bytes inVendors/System.*. We can try to tackle this in a future PR.This PR also keeps a file which is used elsewhere:
and otherwise deletes the vendored
System.Private.CoreLibattributes, because they don't "work":[LibraryImport]attribute drives a source generator, but that generator is only present in .NET 7+, so it does nothing here.Test coverage
No behavior changes expected. All tests should still pass, except for assembly reference changes:
System.Collections.Immutablein .NET 6 instead of the vendored, so assembly reference added thereUnsafein .NET Core 3.1 (and < .NET6), so removed that referenceUnsafe.IsNullRefwhich is only available in .NET 5Unsafefor everything elseOther details
Assembly size comparison
netcoreapp3.1net6.0Estimated size per namespace
Before (
net6.0)After (
net6.0)