-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Determine the order of serializers. #1052
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
Determine the order of serializers. #1052
Conversation
I was reviewing your older Bond PR just yesterday and was thinking about exactly the same problem! In some cases Orleans won't generate its own serializer and external serializer will work (http://dotnet.github.io/orleans/Advanced-Concepts/Serialization -> Auto Generated Serializers). But in a lot of cases it will, and then the code, the way it is written now, will use the Orleans serializer instead of the default one. So we definitely need to solve it. Your proposed solution of a custom attribute is OK, and will work for Bond case I guess. But it will not work for other cases. In other external serializer frameworks, the C# class is auto generated from some language independent spec. Therefore, you cannot annotate it with your custom attribute (you don't want to change/mess with the auto generated code). I have specific serializers examples in mind. So to be general and solve this problem for all serializers we need a different way.
I think I like the last suggestion the most: we explicitly define and document the order in which serializers are used: external first (if multiple externals exist take the first one in the list), then Orleans's one if exist, then fallback one (binary or Json). This is per type of course. |
I don't think the problem is that the codegen is creating serializers, as much as that these serializers are used by default. Instead of starting with a set of pre existing serializers (partially populated with codegen created serializers), I suggest we start with an empty list, and look for the serializer for a type in the following order:
|
This change should fix the problem. I removed the attribute and forced external serializers to be considered prior to falling back to the default serializer. |
@jason-bragg , I think you echoed exactly what I said. :-) |
We should also update the docs explaining the option of external serializers in general, and the new ordering rules as well. |
I had another idea,how to improve this code even more. |
@gabikliot I believe the attribute-based serializer will also have to be in that list, so the default order will be:
|
What is "attribute-based serializer"? |
types that have a CopierMethodAttribute, SerializerMethodAttribute, and DeserializerMethodAttribute defined |
Yes, of course, I forgot about those. |
@gabikliot @Carlm-MS I agree with Gabi's suggestion to generalize this in the future, and have the current order as the default configuration. Still I think that that change could have a little lower priority once we get this PR committed (as there is no reason IMO to not fix this right away and generalize the approach later). |
+1 |
BTW @Carlm-MS, do you happen to have any tests that verify this? I'm running all of our suite, but it still might be nice to have something that asserts the new order, especially since we intend to generalize this in the future (but it should still work in the same way by default). |
@Carlm-MS I'm about to pull the changes locally to rebase and squash (as the 1st commit doesn't add a lot of value after we changed direction). You will still be listed as the author of the 1 commit. Are you cool with that or do you prefer to rebase and squash on your side? |
@jdom I'm fine with it. |
e3139b3
to
73b282c
Compare
|
@@ -2223,6 +2229,8 @@ private static void RegisterSerializationProviders(List<TypeInfo> providerTypes) | |||
return; | |||
} | |||
|
|||
externalSerializers.Clear(); | |||
typeToExternalSerializerDictionary.Clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we actually want to clear everything when registering new serialization providers? shouldn't these be additive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this was just for testing, maybe we should clear these collections when calling InitializeForTesting
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jdom This was intentional. If someone explicitly calls RegisterSerializationProviders, presumably they would want to register those specific providers in the order in the list (which would cause the mapping of types to serializers to be invalidated and the list of serializers to be invalid) . Also, since they are called by the initialization routines, then the state should be initialized.
Not sure I see which line of code this comment refers to, would you mind pointing me to it? |
73b282c
to
9c0ab02
Compare
@jdom SerializationManager::HasOrleansSerialization just added the check to see if the the external serializers handle the type. |
@jdom, you should join the DotNet organization on GH (https://github.com/dotnet), so others can assign issues to you. One can assign issues only on his/project org members. |
@gabikliot We are already figuring it out with .NET Foundation folks. |
This is ready to be merged, right? |
I think @jdom was still reviewing. OK form my side. |
Yes, it’s ready. I didn’t get permissions to commit yet, that's why I didn't do it. But feel free to merge it yourself. |
Determine the order of serializers.
Thank you, @Carlm-MS! |
Codegen, by default, creates serializers for types. This overrides the behavior of external serializers since it explicitly registers those types with the generated serializers. This attribute will prevent serializers from being generated.