mongodb/mongo-csharp-driver — pull request #99 by optimiz3 (2012-04-24 20:06:16+00:00)
Title: Implement CSHARP-451 (Improve deserialization performance by ~22%).

Deserialization CPU performance was suffering because both LookupDiscriminatorConvention and LookupSerializer were being called for nearly every class member. Both functions take out and release the global config read-lock. Profiling showed that around 22% of all CPU time was being spent in ReaderWriterLockSlim.TryEnterReadLock and ReaderWriterLockSlim.ExitReadLock due to these functions.
Fix makes the BsonClassMap and BsonMemberMap cache references to the appropriate IDiscriminatorConvention and IBsonSerializer instances. By doing this, lookups are avoided while maintaining semantic correctness due to the associated BsonClassMap and BsonMemberMap types never changing once constructed. Incorporated much feedback from discussion with Robert to simplify changes.

Other issues addressed:
1. BsonSerializer.Serialize had a bug where a class implementing IBsonSerializable would always be serialized using the IBsonSerializable implemention, even if the implementation was overridden by a registered IBsonSerializer.
2. Modified BsonSerializer to allow only one custom serializer to be registered. This prevents cache consistency issues when a serializer instance is cached within a BsonMemberMap.