Improve allocations in ReflectionXmlSerializationWriter when serializing primitive types#84474
Conversation
|
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
|
@mconnew, @StephenMolloy |
|
|
||
| //char buffer for serializing primitive values | ||
| private readonly char[] _primitivesBuffer = new char[64]; | ||
| protected readonly char[] primitivesBuffer = new char[64]; |
There was a problem hiding this comment.
This is optional - can be private and then we just have another buffer here.
| public abstract partial class XmlSerializationWriter : System.Xml.Serialization.XmlSerializationGeneratedCode | ||
| { | ||
| protected XmlSerializationWriter() { } | ||
| protected readonly char[] primitivesBuffer; |
There was a problem hiding this comment.
This feels a bit weird. Are there other places in ref assemblies where protected fields are exposed?
It will be a little while before we get a chance to review these changes. But assuming they are like the last PR, I would anticipate the improvements are welcome. A couple of notes:
|
|
@StephenMolloy Fair enough. |
|
@TrayanZapryanov - Did I miss something? This draft is for the reflection-based serializer, which is the direction we do want to move. My second point above was responding to
I didn't want you or anybody else to go down that ILGen road since it likely doesn't play a big part in the future. |
|
@StephenMolloy Sorry I somehow misread your statement and decided that you don't like PRs for Xml serialization and have plans to replace it with something else.. Maybe something connected with source generators... |
|
Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it. |
Follow up of #76436
More primitives are serialized into char buffer and then written into writer, instead of serialized to string.
Next step is to use similar methods/approach in XmlSerializationWriterILGen.