Modify XmlSerializators to use typed XmlWriter.WriteValue method#75415
Closed
TrayanZapryanov wants to merge 3 commits intodotnet:mainfrom
Closed
Modify XmlSerializators to use typed XmlWriter.WriteValue method#75415TrayanZapryanov wants to merge 3 commits intodotnet:mainfrom
TrayanZapryanov wants to merge 3 commits intodotnet:mainfrom
Conversation
…ead of converting to string when value is primitive.
TrayanZapryanov
commented
Sep 11, 2022
| _w.WriteValue((ushort)(object)value); | ||
| else if (typeof(T) == typeof(uint)) | ||
| _w.WriteValue((uint)(object)value); | ||
| //else if (typeof(T) == typeof(ulong)) |
Contributor
Author
There was a problem hiding this comment.
If we want to support these also - we need to extend XmlWriter.WriteValue methods with ulong and guid
…erializationWriterILGen
TrayanZapryanov
commented
Sep 12, 2022
| } | ||
|
|
||
| [RequiresUnreferencedCode("Calls WriteCheckDefault")] | ||
| private void WritePrimitive(string method, string name, string? ns, object? defaultValue, SourceInfo source, TypeMapping mapping, bool writeXsiType, bool isElement, bool isNullable) |
Contributor
Author
There was a problem hiding this comment.
writeXsiType was always false in all call sites.
isElement was not used also
Contributor
Author
|
Looks quote promising as results once both PRs are applied:
After:
|
|
Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it. |
This pull request was closed.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Modify XmlSerializators to use typed XmlWriter.WriteValue method instead of converting to string when value is primitive.
Once Optimization goes in, this should reduce allocations.
Here are some benchmarks from performance repo:
BenchmarkDotNet=v0.13.1.1847-nightly, OS=Windows 10 (10.0.19043.1889/21H1/May2021Update)
11th Gen Intel Core i9-11900K 3.50GHz, 1 CPU, 16 logical and 8 physical cores
.NET SDK=7.0.100-preview.7.22377.5
[Host] : .NET 7.0.0 (7.0.22.37506), X64 RyuJIT AVX2
Job-LGCOMF : .NET 8.0.0 (42.42.42.42424), X64 RyuJIT AVX2
PowerPlanMode=00000000-0000-0000-0000-000000000000 Toolchain=CoreRun IterationTime=250.0000 ms
MaxIterationCount=20 MinIterationCount=15 WarmupCount=1
Benchmark : MicroBenchmarks.Serializers.Xml_FromStream_IndexViewModel
Before:
After both PRs are in a branch: