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

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

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • 1.8.2
    • 1.8.1
    • Performance
    • None
    • Windows 7 Professional SP1 x64
      .NET 4.0
    • Fully Compatible

    Description

      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);
      					}
      				}

      Attachments

        1. LookupSerializer.jpg
          219 kB
          Dmitry Naumov

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: