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

Make FindSerializerForType faster #2576

Merged
merged 8 commits into from
Apr 4, 2017

Conversation

alexvaluyskiy
Copy link
Contributor

Related #2566

I've reused some parts of Scala implementation
Before: 1 400 243 ops/s
After: 4 551 167 ops/s

@Horusiath
Copy link
Contributor

Horusiath commented Mar 30, 2017

Looks like DData types serializers have been resolved to NewtonsoftJsonSerializer instead of their custom implementation (which is hyperion-based).

if (serializer == null)
throw new SerializationException($"Serializer not found for type {objectType.Name}");

_serializerMap.Add(type, serializer);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't that become threadsafe collection in presence of updates? In Scala ConcurrentHashMap is used.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also there will be duplicate exception if we first found object on line 251 and then trying to add it back. What the point of this btw?

Copy link
Contributor Author

@alexvaluyskiy alexvaluyskiy Mar 30, 2017

Choose a reason for hiding this comment

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

We will get an exception only if we remove all serializers from all configs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed it to ConcurrentDictionary

Copy link
Member

Choose a reason for hiding this comment

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

Why not just change it to _serializerMap.Add[type] = serializer; ? Becomes an upsert that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

if (_serializerMap.ContainsKey(_objectType) && _objectType.IsAssignableFrom(type))
return _serializerMap[_objectType];
//do a final check for the "object" serializer
if (serializer == null && _serializerMap.ContainsKey(_objectType) && _objectType.IsAssignableFrom(type))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why we need to check that type is subclass of objec?

Copy link
Member

Choose a reason for hiding this comment

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

lol.... it's literally checking to see if we're assignable from object ?

/// </summary>
public class Information
internal class Information
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made it internal

@@ -60,7 +56,7 @@ public static T SerializeWithTransport<T>(ActorSystem system, Address address, F

private readonly Serializer _nullSerializer;

private readonly Dictionary<Type, Serializer> _serializerMap = new Dictionary<Type, Serializer>();
private readonly ConcurrentDictionary<Type, Serializer> _serializerMap = new ConcurrentDictionary<Type, Serializer>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to ConcurrentDictionary

/// <param name="serializerId">TBD</param>
/// <returns>TBD</returns>
public Serializer GetSerializerById(int serializerId)
internal Serializer GetSerializerById(int serializerId)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one should be internal

}
/// <param name="bytes">The array containing the serialized object</param>
/// <returns>The object contained in the array</returns>
public T FromBinary<T>(byte[] bytes) => (T)FromBinary(bytes, typeof(T));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should have this method

/// </remarks>
/// <param name="type">TBD</param>
/// <returns>TBD</returns>
protected static string TypeQualifiedNameForManifest(Type type)
Copy link
Contributor Author

@alexvaluyskiy alexvaluyskiy Mar 30, 2017

Choose a reason for hiding this comment

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

We have an extension method for that. We don't need this method anymore

@Aaronontheweb Aaronontheweb merged commit 1d0d1fb into akkadotnet:dev Apr 4, 2017
@alexvaluyskiy alexvaluyskiy deleted the fastfindserializer branch April 24, 2017 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants