XmlSerializer: route formatted primitive output through span-based raw writer fast path#128505
Draft
Copilot wants to merge 3 commits into
Draft
XmlSerializer: route formatted primitive output through span-based raw writer fast path#128505Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
…r path Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/29c71057-04f8-4c4e-9c5f-5442fe10a352 Co-authored-by: StephenMolloy <19562826+StephenMolloy@users.noreply.github.com>
…w writer fast path Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/29c71057-04f8-4c4e-9c5f-5442fe10a352 Co-authored-by: StephenMolloy <19562826+StephenMolloy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Optimize Xml serialization for primitive objects
XmlSerializer: route formatted primitive output through span-based raw writer fast path
May 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change targets the primitive-write hot path in
XmlSerializationWriter, where formatted values (notablydecimal) were still funneled throughWriteRaw(char[], ...)and could incur avoidable conversions in the underlying writer stack. It adds an internal span-based raw-write path so default raw text writers can consume formatted primitive data directly.Serializer hot-path update
WriteTypedPrimitivenow uses a span path when the writer isXmlWellFormedWriter, passing_primitivesBuffer.AsSpan(0, charsWritten)into an internal raw-write overload.char[]fallback remains for non-XmlWellFormedWritercases.Raw writer pipeline extension
WriteRaw(ReadOnlySpan<char>)toXmlRawWriter(default fallback to existing string-based behavior).WriteRaw(ReadOnlySpan<char>)inXmlWellFormedWriterto preserve state machine behavior and forward to underlying raw writers.Fast-path implementations
XmlUtf8RawTextWriterandXmlEncodedRawTextWriternow override span-based raw writing and feed spans directly into existing raw char-checking/output routines.XmlRawTextWriterGenerator.ttincludeand the generated writer sources.Coverage update
Xml_DecimalArrayAsRoottoXmlSerializerTests.RuntimeOnly.csto exercise primitive-array serialization/round-trip on this path.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
bla/home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet /home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet exec --runtimeconfig System.Private.Xml.Tests.runtimeconfig.json --depsfile System.Private.Xml.Tests.deps.json /home/REDACTED/.nuget/packages/microsoft.dotnet.xunitconsoleREDACTED/2.9.3-beta.26257.113/build/../tools/net/xunit.console.dll System.Private.Xml.Tests.dll -xml testResults.xml -nologo -notrait category=OuterLoop -notrait category=failing e/.dotnet/bash urity.Cryptograp/home/REDACTED/work/runtime/runtime/.dotnet/dotnet /lib/x86_64-linu/home/REDACTED/work/runtime/runtime/artifacts/bin/ILLink.Tasks/Debug/net/illink.dll /usr/bin/../lib/@/tmp/MSBuildTempZLMhIi/tmp0ef4b4df5791499bb66cd3620b8aacff.rsp PORTS(dns block)/home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet /home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet exec --runtimeconfig System.Private.Xml.Tests.runtimeconfig.json --depsfile System.Private.Xml.Tests.deps.json /home/REDACTED/.nuget/packages/microsoft.dotnet.xunitconsoleREDACTED/2.9.3-beta.26257.113/build/../tools/net/xunit.console.dll System.Private.Xml.Tests.dll -xml testResults.xml -nologo -notrait category=OuterLoop -notrait category=failing e/.dotnet/sdk/11.0.100-preview.5.26227.104/MSBuild ORT_SHARED_API -git OS -DHOST_AMD64 e/.dotnet/sdk/11HEAD(dns block)foo/home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet /home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet exec --runtimeconfig System.Private.Xml.Tests.runtimeconfig.json --depsfile System.Private.Xml.Tests.deps.json /home/REDACTED/.nuget/packages/microsoft.dotnet.xunitconsoleREDACTED/2.9.3-beta.26257.113/build/../tools/net/xunit.console.dll System.Private.Xml.Tests.dll -xml testResults.xml -nologo -notrait category=OuterLoop -notrait category=failing e/.dotnet/bash urity.Cryptograp/home/REDACTED/work/runtime/runtime/.dotnet/dotnet /lib/x86_64-linu/home/REDACTED/work/runtime/runtime/artifacts/bin/ILLink.Tasks/Debug/net/illink.dll /usr/bin/../lib/@/tmp/MSBuildTempZLMhIi/tmp0ef4b4df5791499bb66cd3620b8aacff.rsp PORTS(dns block)/home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet /home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet exec --runtimeconfig System.Private.Xml.Tests.runtimeconfig.json --depsfile System.Private.Xml.Tests.deps.json /home/REDACTED/.nuget/packages/microsoft.dotnet.xunitconsoleREDACTED/2.9.3-beta.26257.113/build/../tools/net/xunit.console.dll System.Private.Xml.Tests.dll -xml testResults.xml -nologo -notrait category=OuterLoop -notrait category=failing e/.dotnet/sdk/11.0.100-preview.5.26227.104/MSBuild ORT_SHARED_API -git OS -DHOST_AMD64 e/.dotnet/sdk/11HEAD(dns block)notfound.invalid.corp.microsoft.com/home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet /home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet exec --runtimeconfig System.Private.Xml.Tests.runtimeconfig.json --depsfile System.Private.Xml.Tests.deps.json /home/REDACTED/.nuget/packages/microsoft.dotnet.xunitconsoleREDACTED/2.9.3-beta.26257.113/build/../tools/net/xunit.console.dll System.Private.Xml.Tests.dll -xml testResults.xml -nologo -notrait category=OuterLoop -notrait category=failing e/.dotnet/bash urity.Cryptograp/home/REDACTED/work/runtime/runtime/.dotnet/dotnet /lib/x86_64-linu/home/REDACTED/work/runtime/runtime/artifacts/bin/ILLink.Tasks/Debug/net/illink.dll /usr/bin/../lib/@/tmp/MSBuildTempZLMhIi/tmp0ef4b4df5791499bb66cd3620b8aacff.rsp PORTS(dns block)/home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet /home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet exec --runtimeconfig System.Private.Xml.Tests.runtimeconfig.json --depsfile System.Private.Xml.Tests.deps.json /home/REDACTED/.nuget/packages/microsoft.dotnet.xunitconsoleREDACTED/2.9.3-beta.26257.113/build/../tools/net/xunit.console.dll System.Private.Xml.Tests.dll -xml testResults.xml -nologo -notrait category=OuterLoop -notrait category=failing e/.dotnet/sdk/11.0.100-preview.5.26227.104/MSBuild ORT_SHARED_API -git OS -DHOST_AMD64 e/.dotnet/sdk/11HEAD(dns block)test.test/home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet /home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet exec --runtimeconfig System.Private.Xml.Tests.runtimeconfig.json --depsfile System.Private.Xml.Tests.deps.json /home/REDACTED/.nuget/packages/microsoft.dotnet.xunitconsoleREDACTED/2.9.3-beta.26257.113/build/../tools/net/xunit.console.dll System.Private.Xml.Tests.dll -xml testResults.xml -nologo -notrait category=OuterLoop -notrait category=failing e/.dotnet/bash urity.Cryptograp/home/REDACTED/work/runtime/runtime/.dotnet/dotnet /lib/x86_64-linu/home/REDACTED/work/runtime/runtime/artifacts/bin/ILLink.Tasks/Debug/net/illink.dll /usr/bin/../lib/@/tmp/MSBuildTempZLMhIi/tmp0ef4b4df5791499bb66cd3620b8aacff.rsp PORTS(dns block)/home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet /home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet exec --runtimeconfig System.Private.Xml.Tests.runtimeconfig.json --depsfile System.Private.Xml.Tests.deps.json /home/REDACTED/.nuget/packages/microsoft.dotnet.xunitconsoleREDACTED/2.9.3-beta.26257.113/build/../tools/net/xunit.console.dll System.Private.Xml.Tests.dll -xml testResults.xml -nologo -notrait category=OuterLoop -notrait category=failing e/.dotnet/sdk/11.0.100-preview.5.26227.104/MSBuild ORT_SHARED_API -git OS -DHOST_AMD64 e/.dotnet/sdk/11HEAD(dns block)If you need me to access, download, or install something from one of these locations, you can either: