-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
/// <summary> | ||
/// Cached version of <see cref="dictionary"/>. | ||
/// </summary> | ||
private volatile Dictionary<TKey, TValue> readCache; |
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.
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?
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.
I'll remove it, it's not needed.
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.
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()); |
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.
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?
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.
That's right
4ac050a
to
c931e4a
Compare
LGTM! |
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 aType
and returns a string suitable for use withType.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 eitherDictionary
+lock
orConcurrentDictionary
for our use-cases.This can be merged without squashing.