Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1066

Change BsonElement from a class to a struct

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.0
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • None
    • Minor Change
    • None
    • None
    • None
    • None
    • None
    • None

      If BsonElement were a struct instead of a class then BsonDocument could use less memory (fewer heap objects). BsonDocument stores the elements in a List:

      private List<BsonElement> _elements;
      

      Currently, BsonElement is a class, so a document with N elements uses N + 1 heap objects for the elements (1 for the List and one for each element). If BsonElement were a struct it would use only 1 heap object (for the List), because as a struct the memory for all the elements would be internal to the List (true for all Lists of structs).

      This change is potentially backward breaking for anyone who has written code that uses elements directly. In particular, as a struct we would want the BsonElement class to be immutable, which means we would remove the ability to change the value of an existing element.

      We would appreciate comments from our users letting us know if this small breaking change would affect you or not.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: