[CSHARP-4307] Optimize class and collection deserialization Created: 02/Sep/22  Updated: 20/Jan/23  Resolved: 17/Oct/22

Status: Closed
Project: C# Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Unknown
Reporter: Aleksei Troepolskii Assignee: Boris Dogadov
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CSHARP-4306 Performance optimization for class an... Backlog
Epic Link: Improve Serialization

 Description   

Class deserializer has many work with reflection , excess loop checks, set values to properties produce boxing

Collection deserialization create excess list instead of return the ready one and again - REFLECTION....

I solved these problems:

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.


Generated at Wed Feb 07 21:47:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.