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

BSONArrayBuilder::subXStart, various forms of inefficiency

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.9.0
    • Affects Version/s: 1.6.2, 1.6.3, 1.6.4, 1.7.0, 1.7.1, 1.7.2
    • Component/s: Internal Client
    • Labels:
      None

      BSONArrayBuilder has a few rather serious performance glitches around subarrayStart and subobjStart, specifically:

      These functions require that you provide a 'name' for the element that you wish to start, as a string. As a result, you are forced into a strlen call (to populate StringData) and a strtol call (to convert the string to an integer), and to keep your own external integer counter to convert to a string. This is mostly useless: the common use case here is just to start the next element in the series, and BSONArrayBuilder already keeps an internal counter.

      I think you could just have:

      subarrayStart(); // auto-increment to next index
      subobjStart(); // auto-increment to next index
      subarrayStart(size_t index); // ok, you want to do something fancy, use 'fill', etc. Still no need for strtol
      subobjStart(size_t index); // as above
      subarrayStart( const StringData& strIndex); // do the whole complex dance with strtol, fill, etc.
      subobjStart( const StringData& strIndex); // as above.

      This would let most users never have to worry about this stuff at all (since they are starting array elements in order), let more advanced users use a more efficient mechanism that avoids string processing when using offsets by providing integer offsets, and finally provide a way forward for the more general case.

      Finally, what should the behavior be if you specifiy a 'name' (index) for an element and you are already beyond that many elements in the array? It appears that the provided name'is just ignored in this case. Perhaps that should be an error?

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            andrew.morrow@mongodb.com Andrew Morrow (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: