[CSHARP-1111] Reduce the number of serialization contexts that must be created Created: 20/Nov/14  Updated: 02/Apr/15  Resolved: 11/Dec/14

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

Type: Improvement Priority: Major - P3
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

In our current 2.0 design, a new serialization context must be created every time we descend one level in the hierarchy of the document being serialized or deserialized.

Most of the time, the only thing that is changing is the nominal type. Perhaps it would be better to move the nominal type out of the serialization context and back as a parameter of the Serialize/Deserialize methods, which would allow us to use the same context over and over, thus reducing GC pressure.



 Comments   
Comment by Robert Stam [ 11/Dec/14 ]

There were more values besides just the nominalType that needed to be moved out of the serialization context, so we introduced Args classes to hold them.

In summary:

BsonDeserializationContext/BsonSerializationContext hold values that remain constant all the way down the call stack during serialization (although in some rare cases we might modify the context part way down)

BsonDeserializationArgs/BsonSerializationArgs hold values that only apply to one level of the call stack.

The Args classes are small structs so creating them does not increase GC pressure.

Comment by Githook User [ 11/Dec/14 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1111: Remove Parent property from serialization contexts.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/f8f0904d8c856321b218d816244d08b827323c9c

Comment by Githook User [ 11/Dec/14 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1111: Split serialization contexts into two parts: a context that remains the same throughout the entire call tree, and args that apply to one serialization level only. The goal is to reduce GC pressure caused by constant creation of child contexts.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/5837692d0bb0faf134e6b7b5f8168a964d39bd60

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