Skip to content

Use Json.NET contract resolver to fix serialization performance issue #1080

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

Merged

Conversation

sean-rose
Copy link
Contributor

Commit bbab9b9 for issue #861 introduced (or rather exacerbated) a JSON serialization performance problem with specifying a list of converters via JsonSerializerSettings.

From the Json.NET performance tips (https://www.newtonsoft.com/json/help/html/Performance.htm#JsonConverters):

There is, however, a small amount of overhead; the CanConvert method is called for every value to check whether serialization should be handled by that JsonConverter.

Before commit bbab9b9 that was only being done for RFC3339DateTimeConverter, which had a relatively quick CanConvert method. Commit bbab9b9 added ExplicitNullConverter with a slower CanConvert method that uses reflection. In my testing with a sizeable data set, JSON serialization was 5x slower and deserialization was 4x slower than before.

This change restores the prior JSON serialization performance.

Commit bbab9b9 for issue googleapis#861 introduced (or rather exacerbated) a JSON serialization performance problem with specifying a list of converters via JsonSerializerSettings.

From the Json.NET performance tips (https://www.newtonsoft.com/json/help/html/Performance.htm#JsonConverters):

   > There is, however, a small amount of overhead; the CanConvert method is called for every value to check whether serialization should be handled by that JsonConverter.

Before commit bbab9b9 that was only being done for RFC3339DateTimeConverter, which had a relatively quick CanConvert method.  Commit bbab9b9 added ExplicitNullConverter with a slower CanConvert method that uses reflection.  In my testing with a sizeable data set, JSON serialization was 5x slower and deserialization was 4x slower than before.

This change restores the prior JSON serialization performance.
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Aug 31, 2017
Copy link
Contributor

@chrisdunelm chrisdunelm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good :) Thanks very much. I'll merge shortly.

@chrisdunelm chrisdunelm merged commit 064067a into googleapis:master Aug 31, 2017
@chrisdunelm
Copy link
Contributor

We're expecting to release v1.29.1 in the next day or two (mainly to fix #464), which will include this improvement. Thanks :)

@chrisdunelm
Copy link
Contributor

v1.29.1, containing this fix, has now been released and pushed to nuget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants