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

BsonDocument should postpone creating internal dictionary until document grows large enough

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • 2.0
    • None
    • BSON
    • None

    Description

      BsonDocument has two internal fields for its implementation:

      private List<BsonElement> _elements;
      private Dictionary<string, int> _indexes; // maps names to positions

      Considering that for small documents a linear search of the _elements List can be faster than a Dictionary lookup, we could postpone creating the dictionary until the document grew large enough to make it worthwhile, and fall back to linear searches when the dictionary doesn't yet exist. This would both save memory and be faster for smaller documents.

      We would have to experiment to find the threshold at which to create the dictionary. A similar class in .NET (HybridDictionary) uses a threshold of 8, so that gives us an idea of the approximate value for the threshold.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: