Skip to content
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 polymorphic performance of (de)serialization #38637

Closed
steveharter opened this issue Jun 30, 2020 · 3 comments · Fixed by #42538
Closed

Improve polymorphic performance of (de)serialization #38637

steveharter opened this issue Jun 30, 2020 · 3 comments · Fixed by #42538
Assignees
Labels
Milestone

Comments

@steveharter
Copy link
Member

steveharter commented Jun 30, 2020

Scenarios that use typeof(System.Object) are significantly slower since:

  • During serialization, the object's type is obtained and a dictionary lookup is performed to obtain the correct "converter". The dictionary lookup is expensive. It is possible to improve the caching here, especially when serializing a collection of objects where all elements are the same Type.
  • During deserialization, the converter for System.Object creates a JsonElement to represent the object. For primitive types like boolean, the cost is high. It is possible to improve performance here by avoiding extra array pool allocations that are created and then released via Dispose(), so going from this:
using (JsonDocument document = JsonDocument.ParseValue(ref reader))
{
    return document.RootElement.Clone();	
}

to

return JsonElement.Parse(ref reader);
@steveharter steveharter added this to the 5.0.0 milestone Jun 30, 2020
@steveharter steveharter self-assigned this Jun 30, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Jun 30, 2020
@steveharter steveharter removed the untriaged New issue has not been triaged by the area owner label Jun 30, 2020
@steveharter steveharter modified the milestones: 5.0.0, Future Aug 10, 2020
@steveharter
Copy link
Member Author

Moving to future

@steveharter steveharter removed their assignment Aug 11, 2020
@steveharter
Copy link
Member Author

Also see related issue where we improved perf somewhat in 3.1 #31103

@steveharter
Copy link
Member Author

steveharter commented Sep 4, 2020

See also #29690 which may add functionality to not use JsonElement for these scenarios.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants