Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-2303

Regression in LazyBSONObject.entrySet() performance in the 3.x driver

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 3.0.0
    • Fix Version/s: 3.4.0
    • Component/s: BSON, Performance
    • Labels:
      None

      Description

      There is a regression in the performance of LazyBSONObject.entrySet() in the 3.x driver vs. the 2.x driver.

      The below runs in ~80ms with the 2.14 driver and ~8000ms with the 3.3 driver.

      package misc;
       
      import com.mongodb.*;
       
      import java.util.*;
      import java.util.Map.Entry;
       
      import org.bson.*;
       
      public class LazyBsonWalk {
       
          public static void main(String args[]) throws Exception {
              MongoClient mongo = new MongoClient();
              DBCollection coll = mongo.getDB("test").getCollection("doc");
              coll.drop();
       
              coll.setDBDecoderFactory(LazyDBDecoder.FACTORY);
       
              coll.insert(generateDoc());
       
              long start = System.currentTimeMillis();
              walkLazyBSONObject((LazyBSONObject)coll.findOne());
              long end = System.currentTimeMillis();
       
              System.out.println(end - start);
          }
       
          public static void walkLazyBSONObject(LazyBSONObject lazyObj) {
              Set<Entry<String, Object>> set = lazyObj.entrySet();
       
              for(Entry<String, Object> entry : set) {
       
                  Object value = null;
                  value = entry.getValue();
       
                  if (value instanceof LazyBSONObject) {
                      walkLazyBSONObject((LazyBSONObject)value);
                  }
              }
          }
       
          public static DBObject generateDoc() {
              DBObject obj = new BasicDBObject();
       
              for (int i = 0; i < 10; i++) {
                  DBObject obji = new BasicDBObject();
       
                  for (int j = 0; j < 10; j++ ) {
                      DBObject objj = new BasicDBObject();
       
                      for (int k = 0; k < 100; k++) {
                          DBObject data = new BasicDBObject();
                          data.put("clicks", 0);
                          data.put("impressions", 1);
                          data.put("revenue", 100);
       
                          objj.put(String.valueOf(k), data);
                      }
                      obji.put(String.valueOf(j), objj);
                  }
                  obj.put(String.valueOf(i), obji);
              }
       
              return obj;
          }
      }
      

        Attachments

          Activity

            People

            Assignee:
            jeff.yemin Jeffrey Yemin
            Reporter:
            steve.briskin Steve Briskin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: