Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-750

Improve performance of serialization/deserialization of types serialized as BSON arrays

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.8.2
    • Affects Version/s: 1.8.1
    • Component/s: Performance
    • Labels:
      None
    • Environment:
      Windows 7 Professional SP1 x64
      .NET 4.0
    • Fully Compatible

      When serializing array of value types there is no need to lookup for serializer for every item, because it is homogeneous. This saves us some cpu cycles but most benefit may be achieved when multiple threads are doing serialization, like in my multi-threaded insert benchmark. The suggest fix allows to avoid extra-contention on ReaderWriterLockSlim inside BsonSerializer.

      				if (typeof(T).IsValueType)
      				{
      					var serializer = BsonSerializer.LookupSerializer(typeof(T));
      					foreach (var item in array)
      					{
      						serializer.Serialize(bsonWriter, typeof (T), item, options);
      					}
      				}
      				else
      				{
      					foreach (var item in array)
      					{
      						BsonSerializer.Serialize(bsonWriter, typeof (T), item, itemSerializationOptions);
      					}
      				}
      

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            dnaumov Dmitry Naumov
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: