Minor deserialization perf improvements for collections#40889
Minor deserialization perf improvements for collections#40889steveharter merged 2 commits intodotnet:masterfrom
Conversation
| { | ||
| yield return (TDeclaredProperty)item; | ||
| } | ||
| } |
There was a problem hiding this comment.
Unrelated to your PR, but you might consider using Enumerable.Cast instead of this method:
corefx/src/System.Linq/src/System/Linq/Cast.cs
Lines 33 to 55 in bca5498
There was a problem hiding this comment.
@layomia can you go through this code and update the casts per suggestion above?
| !creator.CreateImmutableDictionary(sourceDictionary, out collection)) | ||
| { | ||
| ThrowHelper.ThrowJsonException_DeserializeUnableToConvertValue(collectionType, jsonPath); | ||
| ThrowHelper.ThrowJsonException_DeserializeUnableToConvertValue(collectionType, state.JsonPath); |
There was a problem hiding this comment.
nit: I was playing around with the deserializer code, and I think JsonPath should be changed to a method rather than being a property (GetJsonPath()). Making it a property gives the wrong impression that its cheap, when it is actually doing the work to build the path.
It might be worth taking pieces from this commit and incorporate it into yours:
ahsonkhan@c76bbd6
There was a problem hiding this comment.
Thanks. Yes the main reason for this PR is because JsonPath is not cheap. I'm make the changes.
Also making a method vs property affects debuggability, so I'll update the [DebuggerDisplay] to call the method.
| // sourceList argument then uses the delegateKey argument to identify the appropriate cached | ||
| // CreateRange<TRuntimePropertyType> method to create and return the desired immutable collection type. | ||
| public override IDictionary CreateImmutableDictionaryInstance(Type collectionType, string delegateKey, IDictionary sourceDictionary, string jsonPath, JsonSerializerOptions options) | ||
| public override IDictionary CreateImmutableDictionaryInstance(ref ReadStack state, Type collectionType, string delegateKey, IDictionary sourceDictionary, JsonSerializerOptions options) |
There was a problem hiding this comment.
Why re-order the parameters? Why not replace the string jsonPath parameter with ref ReadStack state in the same order? This applies for all the changes here.
There was a problem hiding this comment.
The ReadStack and jsonPath parameters are not equivalent.
Having ReadStack first is being consistent with the calling methods (e.g. CreateFromDictionary(ref ReadStack state, IDictionary sourceDictionary, JsonSerializerOptions options)
|
I'll create a PR incorporating #40889 (comment) & applicable pieces from #40889 (comment) when this PR is merged. |
Benchmarks for deserializing single collection
System.Text.Json.Serialization.Tests.ReadJson<ImmutableDictionary<string, string>>