-
Type: Improvement
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 1.8.1
-
Component/s: Performance
-
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); } }