Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-43953

Drop backing BSON in Document when possible

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Do
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
    • Query 2019-11-18, Query 2019-12-02, Query 2020-03-23, Query 2020-04-06

      Documents store a backing BSON object in addition to a cache of fields which have already been examined. This means they may be ~2x the size of the actual user document they represent. This makes copying them slower (we call getOwned() when crossing the find/agg membrane), and increases memory consumption. We should make an effort to drop this backing BSON when it is no longer necessary to hold onto.

      If this ticket gets scheduled, someone should think very hard about what conditions the backing BSON can be dropped are. I would start with the following:

      1) The backing BSON has been fully traversed (DocumentStorage::_bsonIt has reached the end)
      AND
      2) The metadata has been loaded from the backing BSON or the backing BSON has no metadata
      AND
      3) The original BSON will not be returned to the user. i.e. the Document has been modified, will be modified, or will be discarded. If this is the case then we'll never take the toBson() fast path which uses the original backing BSON.

      Point (3) is pretty broad, but for a first implementation we could only consider cases where the Document is already modified.

            Assignee:
            ian.boros@mongodb.com Ian Boros
            Reporter:
            ian.boros@mongodb.com Ian Boros
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: