Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/MongoDB.Bson/Serialization/BsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,20 @@ internal static bool IsDiscriminatorConventionRegisteredAtThisLevel(Type type)
/// <returns>True if the type is discriminated.</returns>
public static bool IsTypeDiscriminated(Type type)
{
var typeInfo = type.GetTypeInfo();
return typeInfo.IsInterface || __discriminatedTypes.Contains(type);
if (type.GetTypeInfo().IsInterface)
{
return true;
}

__configLock.EnterReadLock();
Copy link
Member

Choose a reason for hiding this comment

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

Could you please double-check if introducing this synchronization affects performance. If so, we could replace HashSet<Type> with ConcurrentDictionary<Type, bool>.

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 changed it to use a ConcurrentDictionary, thanks for taking time to do the benchmarks :)

try
{
return __discriminatedTypes.Contains(type);
}
finally
{
__configLock.ExitReadLock();
}
}

/// <summary>
Expand Down