-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Refactor root-level serialization logic and polymorphic value handling. #72789
Conversation
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsRefactors the root-level serialization/deserialization routines so that
|
...em.Text.Json.Tests/Serialization/CustomConverterTests/CustomConverterTests.Dynamic.Sample.cs
Show resolved
Hide resolved
...libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/CastingConverter.cs
Show resolved
Hide resolved
...raries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.ByteArray.cs
Show resolved
Hide resolved
...tem.Text.Json/src/System/Text/Json/Serialization/Converters/JsonMetadataServicesConverter.cs
Show resolved
Hide resolved
...tem.Text.Json/src/System/Text/Json/Serialization/Converters/JsonMetadataServicesConverter.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.WriteCore.cs
Outdated
Show resolved
Hide resolved
...ibraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Document.cs
Show resolved
Hide resolved
...libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Helpers.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Span.cs
Show resolved
Hide resolved
...raries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.ByteArray.cs
Show resolved
Hide resolved
...raries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.ByteArray.cs
Outdated
Show resolved
Hide resolved
...raries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.ByteArray.cs
Show resolved
Hide resolved
...braries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Document.cs
Show resolved
Hide resolved
...braries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Document.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfoOfT.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfoOfT.cs
Show resolved
Hide resolved
It must be noted that this change introduces a slight performance regression, specifically when it comes to serializing small root-level System.Text.Json.Serialization.Tests.WriteJson<Int32>.SerializeObjectProperty
Fundamentally, it is caused by this change removing the hardcoded polymorphic serialization for root-level I've been able to recover some of the performance losses by employing a secondary LRU cache specifically used for root-level polymorphic types. I think we should merge this PR and accept the performance regression, as it is essential for getting #72187 and #72681 fixed. The performance regression only impacts small, root-level polymorphic values and does not affect the statically typed APIs or the source generator which are more performance-minded. |
If incorrect code or code wrote under wrong assumptions is faster then there is no perf regression to me. We should baseline from correct code. If there are any quick wins to gain the perf back then even better |
80a1fa9
to
97a8b7a
Compare
I made a few tweaks to the caching strategy in 97a8b7a, caching the resolved
|
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Helpers.cs
Outdated
Show resolved
Hide resolved
…ion/JsonSerializer.Helpers.cs
Refactors the root-level serialization/deserialization routines so that
JsonSerializerOptions
andJsonTypeInfo<T>
overloads inJsonSerializer
call into common helper methods, ensuring that metadata is being handled consistently regardless of invoked overload.object
values is moved to the converter layer. Fixes System.Text.Json instances of polymorphic types emit type discriminator when serialized asobject
types #72187 and System.Text.Json uses inconsistent polymorphism semantics with customobject
converters #72681.