Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve deserialization performance by ~22%. #97

Closed
wants to merge 1 commit into from

Commits on Apr 21, 2012

  1. Improve deserialization performance by ~22%.

    Deserialization CPU performance was suffering because both LookupDiscriminatorConvention and LookupSerializer were being called for nearly each class member. Both functions take out and release the global config read-lock. Profiling showed that around 25% of all CPU time was being spent in ReaderWriterLockSlim.TryEnterReadLock and ReaderWriterLockSlim.ExitReadLock due to these functions.
    
    Fix makes the BsonClassMap and BsonMemberMap persist references to the appropriate IDiscriminatorConvention and IBsonSerializer singletons.  By doing this, lookups are avoided while maintaining semantic correctness due to the associated BsonClassMap and BsonMemberMap types never changing once constructed.
    
    Also introduced is the FastSingleton class, which extends the existing runtime singleton logic as follows:
    1.	Enables more static singleton binding both at compile time and when using generics.
    2.	Enables lazy singleton instantiation
    3.	Decouples singleton data structure logic from type-specific instantiation logic.
    4.	Provides structural performance advantages by isolating runtime binding reader/writer locks and dictionaries by use-case.
    Other issues addressed:
    1.	DefaultSerializers are now always lazy-bound. This simplified the implementation by ensuring singletons are only set once in the case where a user has specified a custom serializer.
    2.	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.
    optimiz3 committed Apr 21, 2012
    Configuration menu
    Copy the full SHA
    9444aa8 View commit details
    Browse the repository at this point in the history