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

for-each loop over BSONObj is slower than explicit BSONObjIterator in MatchExpressionParser code

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 3.6.0
    • Fix Version/s: 3.6.7, 3.7.1
    • Component/s: Internal Code
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Backport Requested:
      v3.6
    • Sprint:
      Platforms 2018-01-01, Platforms 2018-01-15
    • Linked BF Score:
      0

      Description

      As a part of SERVER-30761, we refactored parseInExpression() and changed a loop that looked like

      BSONObjIterator iter(theArray);
      while (iter.more()) {
          auto e = iter.next();
          // ...
      }
      

      into

      for (auto e : theArray) {
          // ...
      }
      

      This has caused a performance regression of roughly 5% when parsing a $in, and is apparent with very large in expressions. The real fix seems like achieving performance parity between the two ways to iterate through a BSONObj, but I'm not sure how much we want to dive down the rabbit hole in terms of seeing the machine code that's generated by the two constructs.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              redbeard0531 Mathias Stearn
              Reporter:
              kyle.suarez Kyle Suarez
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: