-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
@@ -39,7 +39,7 @@ public abstract class XmlSerializationWriter : XmlSerializationGeneratedCode | |||
private bool _escapeName = true; | |||
|
|||
//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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is optional - can be private and then we just have another buffer here.
@@ -585,6 +585,7 @@ protected partial class Fixup | |||
public abstract partial class XmlSerializationWriter : System.Xml.Serialization.XmlSerializationGeneratedCode | |||
{ | |||
protected XmlSerializationWriter() { } | |||
protected readonly char[] primitivesBuffer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.