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

Add message type resolver #42428

Merged
merged 5 commits into from
Jul 6, 2022
Merged

Add message type resolver #42428

merged 5 commits into from
Jul 6, 2022

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented Jun 26, 2022

Replaces MessageConverter with contract resolver using dotnet/runtime#63686.

cc @eiriktsarpalis @krwq

@JamesNK JamesNK added the area-grpc Includes: GRPC wire-up, templates label Jun 26, 2022
@JamesNK
Copy link
Member Author

JamesNK commented Jun 28, 2022

Perf with the resolver is much better than the converter.

|                     Method |     Mean |   Error |  StdDev |        Op/s |  Gen 0 | Gen 1 | Gen 2 | Allocated |
|--------------------------- |---------:|--------:|--------:|------------:|-------:|------:|------:|----------:|
| ReadMessage_JsonSerializer | 386.7 ns | 4.50 ns | 4.21 ns | 2,586,310.5 | 0.0005 |     - |     - |     160 B | <- converter
| ReadMessage_JsonSerializer | 213.3 ns | 0.77 ns | 0.68 ns | 4,687,918.1 | 0.0002 |     - |     - |      80 B | <- resolver
|  ReadMessage_JsonFormatter | 449.7 ns | 3.71 ns | 3.10 ns | 2,223,474.1 | 0.0019 |     - |     - |     584 B |

|                      Method |     Mean |   Error |  StdDev |        Op/s |  Gen 0 | Gen 1 | Gen 2 | Allocated |
|---------------------------- |---------:|--------:|--------:|------------:|-------:|------:|------:|----------:|
| WriteMessage_JsonSerializer | 296.0 ns | 0.82 ns | 0.72 ns | 3,378,463.0 | 0.0010 |     - |     - |     304 B | <- converter
| WriteMessage_JsonSerializer | 167.6 ns | 0.75 ns | 0.63 ns | 5,965,374.0 | 0.0007 |     - |     - |     224 B | <- resolver
|  WriteMessage_JsonFormatter | 166.4 ns | 0.65 ns | 0.58 ns | 6,010,917.3 | 0.0012 |     - |     - |     368 B |

@JamesNK
Copy link
Member Author

JamesNK commented Jul 2, 2022

Review please 🙏 @brunolins16 @halter73 @BrennanConroy @captainsafia

Copy link
Member

@BrennanConroy BrennanConroy left a comment

Choose a reason for hiding this comment

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

Mostly fine, I have an issue with the testing though

""field_name"": ""A field name""
}";

AssertReadJson<HelloRequest>(json);
Copy link
Member

Choose a reason for hiding this comment

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

I dislike this assert, it's basically testing that manual deserialize (with custom options) and our custom JsonParser deserialize create equal output, which doesn't really mean anything since they should be the same thing essentially. We really should be asserting value(s) on HelloRequest are set to the expected value(s).

Copy link
Member Author

Choose a reason for hiding this comment

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

It validates that our JSON functionality matches what is built into Google.Protobuf. The generated objects have an Equals method that does a deep check to validate they're equivalent.

I'll add a couple of manual asserts to sanity check that deserialization is working as expected, but I don't want to assert everything. We know that Google.Protobuf is doing the right thing and if we're equal to it then the code is good.

FieldName = "A field name"
};

AssertWrittenJson(helloRequest,
Copy link
Member

Choose a reason for hiding this comment

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

Same issue with these tests


foreach (var field in fields)
{
mappings.Remove(field.JsonName);
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need add an entry to the dictionary with the JsonName if that will be discarded here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've expanded the comments

Copy link
Member

@brunolins16 brunolins16 left a comment

Choose a reason for hiding this comment

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

🚀

JsonConverterHelper.GetFieldType(field),
name);

if (isWritable)
Copy link
Member

Choose a reason for hiding this comment

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

nit: I was expecting the same as @krwq. Maybe change the parameter name to something like isSerializable

…nscoding/Internal/Json/MessageTypeInfoResolver.cs

Co-authored-by: Stephen Halter <[email protected]>
@JamesNK JamesNK enabled auto-merge (squash) July 6, 2022 01:04
…nscoding/Internal/Json/MessageTypeInfoResolver.cs
@JamesNK JamesNK merged commit 7650c58 into main Jul 6, 2022
@JamesNK JamesNK deleted the jamesnk/contractresolver branch July 6, 2022 02:49
@ghost ghost added this to the 7.0-preview7 milestone Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-grpc Includes: GRPC wire-up, templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants