From b3158f3da2f76f1596801c2729dd94aa80cc409a Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Thu, 4 Aug 2022 14:08:23 +0100 Subject: [PATCH] Fix performance regression introduced in object deserialization --- .../Text/Json/Serialization/JsonConverterOfT.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs index 02021bdc8eb9f2..7959c76f40f420 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs @@ -216,6 +216,20 @@ internal bool TryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSeriali bool isContinuation = state.IsContinuation; bool success; + if ( +#if NETCOREAPP + !typeof(T).IsValueType && +#endif + CanBePolymorphic) + { + // Special case object converters since they don't + // require the expensive ReadStack.Push()/Pop() operations. + Debug.Assert(this is ObjectConverter); + success = OnTryRead(ref reader, typeToConvert, options, ref state, out value); + Debug.Assert(success); + return true; + } + #if DEBUG // DEBUG: ensure push/pop operations preserve stack integrity JsonTypeInfo originalJsonTypeInfo = state.Current.JsonTypeInfo;