Performance optimization for class and collections deserialization

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: BSON, Performance
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Class deserializer has many work with reflection, set properies produces boxing, has many loop checks and so on...

      Collection deserializer always create new list after deserialization insead of return ready one. And again - REFLECTION.

      I solve this problem and get about 35% perf up in my cases with huge dto objects:

      https://github.com/mongodb/mongo-csharp-driver/pull/871

      1. optimized create instance - without reflection
      2. optimized set values to properties- without reflection, boxing, interface virtualization impact (for Deserialize Call)
      3. optimized collection deserialization- in most cases we can just return prepared List, in some other cases - removed reflection
      4. cache IsReadonly
      5. dont call SetRequiredFields if required fields does not exists (flag of required fields exist was cached)
      6. seporate deserialization of classes with default constructor and classes with creatorMap (to get rid of null checks)
      7. add generic BsonMemberMap for some optimizations above
      8. fix one test , that used local culture in Parse method and failed
        var expectedResult = decimal.Parse(expectedResultString, CultureInfo.InvariantCulture); – pass culture here

       

      Links:

      1) PR: https://github.com/mongodb/mongo-csharp-driver/pull/871

      2) Test Project: https://github.com/troepolik/testMongoDBPerformance

      just set reference to BSON project, sure you set release mode and run, and press to repeate several times to see statistics, then switch to my optimized project. 

      Sugestion: press repeat in moment when CPU% is low.

              Assignee:
              Unassigned
              Reporter:
              Aleksei Troepolskii
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: