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

Serialize Type instances without requiring registration #2952

Merged
merged 3 commits into from
Apr 18, 2017

Conversation

ReubenBond
Copy link
Member

Currently, Types need to be registered by SerializationManager.FindSerializationInfo(..) before they can be serialized over the wire.

This PR removes that requirement.

Includes a utility class, RuntimeTypeNameFormatter which takes a Type and returns a string suitable for use with Type.GetType which does not include assembly metadata other than assembly name.

If it's preferred, I can remove the CachedReadConcurrentDictionary. In my benchmarks I find that it's significantly better than either Dictionary + lock or ConcurrentDictionary for our use-cases.

This can be merged without squashing.

@ReubenBond ReubenBond changed the title Serialize Type instances without requiring registeration Serialize Type instances without requiring registration Apr 17, 2017
/// <summary>
/// Cached version of <see cref="dictionary"/>.
/// </summary>
private volatile Dictionary<TKey, TValue> readCache;
Copy link
Member

Choose a reason for hiding this comment

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

Is there a real need for volatile here? Just want to reduce the complexity if it's not.
Because it looks like if you remove volatile, you still can read your writes, and if another thread wants to access it, it probably doesn't matter that the cache was stale (otherwise more attention needs to be paid to when you invalidate the cache, which in this case it looks like is after you modify it, so there are still chances that the cache is stale when read from another thread, even with the volatile).
Or am I missing some edge case?

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'll remove it, it's not needed.

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 fixed it, squashed, and force-pushed so that this can be merged as 3 commits

}

internal static object DeserializeType(Type expected, IDeserializationContext context)
{
return context.SerializationManager.ResolveTypeName(context.StreamReader.ReadString());
return Type.GetType(context.StreamReader.ReadString());
Copy link
Member

Choose a reason for hiding this comment

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

I assume you chose to use Type.GetType as opposed to TypeUtils.ResolveType since the type is always qualified with the assembly name, hence assembly loading is not an issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's right

@ReubenBond ReubenBond force-pushed the fix-type-name-formatting branch from 4ac050a to c931e4a Compare April 18, 2017 01:01
@attilah attilah self-assigned this Apr 18, 2017
@attilah
Copy link
Contributor

attilah commented Apr 18, 2017

LGTM!

@jdom jdom merged commit 51a0607 into dotnet:master Apr 18, 2017
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants